Test case Import

Documentazione •
In questo articolo

Test case import

The type of test that will be analyzed will be suitable for importing the data contained in a CSV file.

To create a test case for an import extension, a series of requirements are required:

  • Developed a function that imports CSV file data into the Banana accounting software.
  • You have created a couple of CSV files with the data inside structured according to a syntax explained on this page, to be used as a test for the method that will be illustrated for carrying out the tests.
  • The creation of functions to do the test.

Functions that imports CSV file data into Banana

function exec(inText){
	// Convert a CSV file to an array of arrays.
	// The parameters are: text to convert, value separator, delimiter for text values
	var csvFile = Banana.Converter.csvToArray(inText, ',', '"');
	//Convert a table (array of arrays) to a tsv (tab separated values) file
	var tsvFile = Banana.Converter.arrayToTsv(csvFile);
    return tsvFile;

Structure data syntax of CSV file

This syntax permit to import the registration and the amount of registration in Banana accounting.

There are specific name of the columns in file CSV:

  • Date.
  • Description.
  • Income.
  • Expenses.

This is an example of what do you want obtain from CSV file:


2024-01-01     Registration Income example      900.00     
2024-01-31Registration Expense example 100.00       


The file CSV have to structured as this example:

"2024-01-01","Income example","900.00",""
"2024-01-31","Registration Expense example","","100.00"

Creation of function testing import data from CSV

Create your file in your folder project "test" with the name of your file of extension: "nameExtensionImport.test.js".

Write the metadata for creation your test, an example:

// @id = nameExtensionId.test.test
// @api = 1.0
// @pubdate = 2024-04-05
// @publisher = Banana.ch SA
// @description = <TEST nameExtensionId.test.test>
// @task = app.command
// @doctype = *.*
// @docproperties = 
// @outputformat = none
// @inputdataform = none
// @timeout = -1
// @includejs = extensionImport.js

Write the functions and instance of your test:

Test.registerTestCase(new TestExtensionImport());
function TestExtensionImport() { }
// This method will be called at the beginning of the test case
TestExtensionImport.prototype.initTestCase = function () {
// This method will be called at the end of the test case
TestExtensionImport.prototype.cleanupTestCase = function () {
// This method will be called before every test method is executed
TestExtensionImport.prototype.init = function () {
// This method will be called after every test method is executed
TestExtensionImport.prototype.cleanup = function () {
TestExtensionImport.prototype.testImport = function(){
	//Path of your file csv to testing
    var fileName = "file:script/../test/testcases/csv_test_transaction.csv";
    //Returns an object of type Banana.IO.LocalFile that represents the requested file. 
    //You get a reference to the specified CSV file.	
    var file = Banana.IO.getLocalFile(fileName);
    // Verify that the file exists.
    var fileContent = file.read();
    // Verify that the contents of the file were read correctly.
    // Run a function called 'exec' on the contents of the file.
    var transactions = exec(fileContent, true);
    //Add transactions to the CSV logger.
    this.testLogger.addCsv('', transactions);

Subsequently, having implemented and followed all these steps and after having built and installed the extension on Banana:

If you want to try the extension you created it will be able to import recordings in Banana, when you start the extension, you will be asked for the path to where the csv file is located and then to define the income and expense accounts.
To view the import function you must have opened a file where you want to import the recordings (you can also try a file created by default with double entry) click on the "Actions" menu at the top, choose Import: "Transactions" and from here you can select the developed extension and path.

To test the extension, you will have to access the Banana "Manage Extensions" menu, then select the developed extension in the Installed menu and click Run test.


Dicci come possiamo aiutarti meglio
Se le informazioni contenute in questa pagina non sono quelle che cerchi, non sono sufficientemente chiare o non sono aggiornate, facci sapere.

Condividi questo articolo: Twitter | Facebook | LinkedIn | Email