Banana.Test.Logger

Documentation •
In this article

The class Banana.Test.Logger contains methods to log test results.

Methods

addSection(key)

This method inserts a new section named key in the test results. A section is like a chapter 1. A section ends at the end of the test or when the method addSection is called again.

addSubSection(key)

This method inserts a new subsection named key in the test results. A section is like a chapter 1.1. A subsection ends at the end of the test or when the methods addSection or addSubSection are called again.

addSubSubSection(key)

This method inserts a new subsubsection named key in the test results. A section is like a chapter 1.1.1. A subsubsection ends at the end of the test or when the methods addSection, addSubSection or addSubSubSection are called again.

addComment(key)

This method inserts a comment in the test results. Test comments are discarded when comparing with the expected test results.

addCsv(key, table [, columns, separator, comment])

This method inserts the content of a csv text (comma separated values) in the test results.

The optional argument columns let you specify the subset of columns to output and in which order.
The optional argument separator if defined is used as the value's separator. If it is not defined the programm automatically determines the separator from one of '\t' (tabulator), ',' (comma) and ';' (semicolon).



// This output all columns
Test.logger.addTable("This is a table", Banana.document, columns);
// This output only the columns Date, Description and Amount 
Test.logger.addTable("This is a table", Banana.document, ["Date", "Description", "Amount"]);

addInfo(key, value)

This method inserts an information in the test results. Test informations are discarded when comparing with the expected test results. Compared to addComment' the key/value information is printed in case you publish the latex result as a pdf.



Test.logger.addInfo("Current date", new Date().toLocaleDateString());

addFatalError(key)

This method inserts a fatal error in the test. If a fatal error is inserted, event in case the results are identical to the expected results, the test fails, and the error message reported to the test differences.



Test.logger.addFatalError("This is a fatal error message");

addJson(key, jsonString [, comment])

This method inserts a json string in the test results. The json string is formatted with identation and the formatted string outputted line by line. If the jsonString contains 'carriage return' characters, then it will be outputted as it is. If the string is not a valid json, the string is outputted as it is.



var obj = {
   'count': 100,
   'color': "yellow"
};
Test.logger.addJsonValue("Param", JSON.stringify(obj));

addKeyValue(key, value [, comment])

This method inserts a test value in form of key and value. The parameter value is of type string.



Test.logger.addKeyValue("Row count", Banana.document.table("Transactions").rowCount);

addPageBreak()

This method inserts a page break. Page Breaks are discarded when comparing with the expected test results. They are just useful when the output is converted to a pdf file for inspecting visually the results.

Since Banana 9.0.4

addRawText(text [, insertEndl])

This method inserts a raw string in the test results without any modification or cleaning.

The optional parameter insertEndl defaults to true. If true an endl in inserted after the text.

addReport(key, report [, comment])

This method inserts the content of a Banana.Report object in the test results. Only the text elements are inserted, not the element's styles.



var report = Banana.Report.newReport("Report title");
report.addParagraph("Hello World !!!", "styleHelloWorld");
Test.logger.addReport("This is a report", report);

addTable(key, table [, columns, comment])

This method inserts the content of a Banana.Table object in the test results.

The optional argument columns let you specify the subset of columns to output and in whitch order.



// This output all columns
Test.logger.addTable("This is a table", Banana.document, columns);
// This output only the columns Date, Description and Amount 
Test.logger.addTable("This is a table", Banana.document, ["Date", "Description", "Amount"]);

addText(key)

This method inserts a simple string in the test results. 

addXml(key, xmlString [, comment])

This method inserts an xml string in the test results. The xml string will be formatted with identation and the formatted string outputted line by line. If the xmlString contains 'carriage return' characters, then it will be outputted as it is. If the string is not a valid xml, the string is outputted as it is.



var xml =
   "<note>" +
      "<to>Pinco</to>" +
      "<from>Pallino</from>" +
      "<heading>Reminder</heading>" +
      "<body>Don't forget me this weekend!</body>" +
   "</note>";
Test.logger.addXmlValue("This is a xml value", xml);

getElapsedTime()

This method returns the elapsed test execution time in milliseconds.

newLogger(logname)

This method returns a new logger, results are written in a separated log file named logname. With this methods you can split test results over several files.

If you have a lot of test results it is advised to split the results over more folder and files. This makes it easy to verify the differences between tests. 

As a generale rule, if you feed the test with two or more *.ac2 files, split the results in separate files.



Test.logger.addText("This test split the results over more files and folder");

// Write results in a new file called testresults 
var testLogger = Test.logger.newLogger("testresults");
testLogger.addText("This text will be written in file testresults.txt");
testLogger.close();

// Write results in a new folder called testgroup
var groupLogger = Test.logger.newGroupLogger("testgroup");

// Write results in a new file called testgroup/testresults1
var test1Logger = groupLogger.newLogger("testresults1");
test1Logger.addText("This text will be written in file testgroup/testresults1.txt");
test1Logger.close();

// Write results in a new file called testgroup/testresults2
var test2Logger = groupLogger.newLogger("testresults2");
test1Logger.addText("This text will be written in file testgroup/testresults2.txt")
test2Logger.close();

groupLogger.close();

newGoupLogger(groupname)

This method returns a new logger, results are written in a separated folder named groupname. With this methods you can split test results over several folders.

If you have a lot of test resutls it is advised to split the results over more folder and files. This makes it easy to verify the differences between tests.

close()

Close the logger for writting and free the reserved system resources (handle, ,memory, ...). This method shold be called for every new logger created with the methods newLogger and newGroupLogger.

Reserved methods

Those methods are used by the BananaApps Test Framework, and should not be directly used.

addTestInfo(key, value)

This method is called automatically by the framework to insert in a test info value like the test name, the running date and time, ...

addTestBegin(key [, comment])

This method is called automatically by the framework to insert in the log file an indication when a test method is started. 

addTestEnd()

This method is called automatically by the framework to insert in the log file an indication when a test method is finished. The framework will also automatically insert information about the elapsed time. 

addTestCaseBegin(key [, comment])

This method is called automatically by the framework to insert in the log file an indication when a test case is started.

addTestCaseEnd()

This method is called automatically by the framework to insert in the log file an indication when a test case is finished. The framework will also automatically insert an information about the elapsed time. 

Tell us how we can help you better
If the information on this page is not what you're looking for, is not clear enough, or is not up-to-date, let us know.

Share this article: Twitter | Facebook | LinkedIn | Email