Product Information > JADE Developer’s Reference > Chapter 17 - Using the JADE Testing Framework > Running Unit Tests In Batch Mode

Running Unit Tests In Batch Mode

You can use the jadclient non-GUI client application to automate the batch running of unit tests passing command line arguments after the endJade parameter to specify your testing and logging requirements.

For details about the jadclient non-GUI client application, see "Running a Non-GUI Client Application using jadclient", in Chapter 1 of the JADE Runtime Application Guide.

To run unit tests in batch mode as a non-GUI application, specify the following parameters in the jadclient program.

jadclient path=database-path
          ini=jade-initialization-file
          [server=multiUser|singleUser|readOnlyUser
          schema=RootSchema
          app=JadeUnitTestBatch
          endJade
          control-file-name
          test-name
          [log-file-name]

The following is an example of the command line that runs a non-GUI client application to run the DailyTests unit test, which is defined in the c:\jade\unittest.xml XML file.

jadclient path=c:\jade\system ini=c:\jade\jade.ini server=multiUser schema=RootSchema app=JadeUnitTestBatch endJade c:\jade\unittest.xml DailyTests c:\jade\logs\unittest.log

The parameters following the endJade parameter are listed in the following table.

Parameter Description
control-file-name Name of the XML control file that defines groups of tests that can be run.
test-name Name of a group of unit tests specified in the control file.
log-file-name Name of a log file used for error and test output. This parameter is optional, as you can also specify the output destination in the control file.

The control file has the following format.

<unitTest>
    <reporter schema="schema name" class="class name" logFile="file name"/>
    <schema name="test schema name" />
    <tests>
        <test name="test name">
        ...
        </test>
    </tests>
</unitTest>

The file can also have the following standard XML declaration header.

<?xml version="1.0" encoding="utf-8"?>

The <reporter> XML element is optional, and is used to specify where the unit test output goes. If a schema and class name are specified, they must correspond to a class that implements the JadeTestListenerIF interface. A transient instance of this class is created and the unit test results are passed to the respective interface methods as the tests are run.

If a logFile is specified and is valid, the unit test results are written to this file. If both the schema and class name are specified, they take precedence and the logFile value is ignored. If neither the schema nor class name are specified or are invalid, error output and test result output are written to the log file specified as the third parameter in the jadclient command.

If the log file is not specified or is invalid, output is written to a file named JadeUnitTest.log in the directory specified by the DefaultLogDirectory parameter in the [JadeMonitorBackground] section of the JADE initialization file.

The <schema> XML element is optional, and is used to specify the default schema in which the unit test classes are defined.

The <tests> XML element, which must be present, contains one or more <test> XML elements. Each <test> XML element is specified, identifying at least one unit test class to be run.

The following example shows the structure of a typical <test> XML element.

<test name="Daily tests">
    <schema name="BankingSchemaTest"/>
    <class name="DepositTests"/>
    <class name="WithdrawalTests>
        <method name="overdrawn"/>
        <method name="exceedsLimit"/>
    </class>
    <class name="AccountTests" includeSubclasses="true"/>
</test>

The <schema> XML element within the <test> XML element is optional, and sets the schema in which the following classes are found, until the end of the <test> block or another schema element is specified. If no <test> block or another schema element is present, the <schema> XML element from the initial part of the file is used. If a valid <schema> XML element is not present, the class specified by a <class> XML element cannot be determined, and these elements are ignored when the test is run.

The <class> XML element, which must have a name attribute corresponding to a valid subclass of the JadeTestCase class, specifies the unit tests to be run for the class. The variants of this class element are as follows.

The <schema> XML element has the optional attributes shown in the following examples.

<schema name="name" runAllTests="true"/> 
<schema name="name" runAllTests="true" includeSubschemas="true"/>

If the runAllTests attribute value is true, all unit test methods of all subclasses of the JadeTestCase class in this schema are run as part of the test. In this case, any <class> XML elements in the test are ignored. If the includeSubschemas attribute value is also true, all unit test methods of all subclasses of the JadeTestCase class in this schema and its subschemas are run as part of the test.

Tests can also include the contents of other tests, by using the <includeTest> element, as shown in the following example.

<includeTest name="test name"/>

This copies the contents of the test specified by the name attribute into the current test.

The jadclient non-GUI client application returns the number of failed tests (with a maximum of 127) as the result code when running the JadeUnitTestBatch application, to enable calling code to determine if the tests ran successfully.