Creating and Running a B-unit Ant Script
Create individual B-unit test cases manually, or save each simulation path you run as a B-unit test file.
If you want to include B-unit testing in an automated build environment, you can create an Ant script to run all the B-unit tests and suites from multiple orchestration projects outside of Process Developer, on the command line. This capability is similar to using the command line BPRD script to deploy a BPR archive to the server.
Prerequisite
You must install the B-Unit Ant Runtime component of the Process Developer before you can run the Ant script. The installation creates a directory containing the runtime files required to run the B-unit Ant script from the command line, outside of Process Developer. You do not need to install Ant separately: the Apache Ant application is installed as part of Process Developer.
Note: Version 1.7.0 of Ant (or above) is required.
Creating a B-unit Ant Script
Use the following procedure to create a B-unit Ant script:
- 1. Ensure your orchestration projects contains one or more B-unit tests or suites, as described in Creating a BPEL Unit Test File.
- 2. Select one B-unit test or suite and right mouse-click to select New > BUnit Ant Script.
- 3. In the Export B-unit Ant Script wizard, select a folder, such as the test folder, and enter a filename. Select Next.
- 4. Select the B-unit tests and suites to include. You can select multiple tests from multiple projects. Also, after you create the script, you can edit it to add more folders of tests.
- 5. Select the B-unit options as desired:
- - Enable Tracing. Controls console logging output for B-unit-specific execution commands.
- - Enable Process Logging. Controls the amount of process execution data to log. The default is none. Enabling the checkbox turns on execution level. If desired, you can manually edit the Ant script to enable execution-data (execution with data) or full logging.
- 6. Select Finish to generate the filename.ant.xml file.
The ant script opens in an editor for you to view or edit. Follow the instructions in the ant script to set the B-unit runtime classpath if you wish to execute this script outside of Process Developer.
You can create a code coverage report when you run a B-unit ant script on the command line. For details, see
Generating a Code Coverage Report.
Notes on Modifying a B-Unit Ant Script
Within the ant script, you can override properties in the individual B-unit files.
- •You can add a file to override the default-B-unit-engine config if needed, such as <config file="engine-configuration.xml" />
- •Nested element <engineProperties> accepts a file relative or absolute path to a properties file with engine config path=value pairs in the format required by java.util.Properties. The file attribute is optional and instead nested <engineProperty name="…" value="…"/> elements can be used to set engine properties. If both the file attribute and the engineProperty elements are used, the elements will override the values in the properties file if the same config path is specified twice.
- •Examples of multiple engine properties:
- - <engineProperty name="Logging" value="urn:ae:execution" />
- - <engineProperty name="CustomFunctions/MyCustomFunction" value="com.test.my.custom.Function" />
Adding Multiple B-unit and B-suite to an Ant Script
Ant provides many ways to specify resource collections, such as a group of B-unit and B-suite files. One example is the following.
<path>
<fileset dir="${test.dir}" includes="**/*.bunit"/>
</path>
For examples, refer to the resource collections section of the Ant 1.7 (or later) documentation.
Running a B-Unit Ant Script
You can run the filename.ant.xml file from within Process Developer if desired. Right-mouse click on the file and select Run As > Ant Build. In the Console you can view trace and log details.
To run the Ant script on the command line, do the following:
- 1. Open a command window.
- 2. Navigate to the file system folder where the ant script is located.
- 3. At the command line prompt, type ant -f filename.ant.xml
Generating a Code Coverage Report
Using a B-unit ant script, you can generate a code coverage report. The report tracks execution paths and display which activities were executed, expressed as percentage of activities executed at least once, in relation to all process's activities.
To generate a code coverage report:
- 1. Create a B-unit ant script as described in Creating and Running a B-unit Ant Script.
- 2. In the <target> named instrument, remove the comments and fill in a resource collection of bpel files. The following example show a simple resource collection:
<target depends="init" name="instrument">
<!-- optional
<coverage activitycoverage="true" linkcoverage="true" />
-->
<bunit-instrument>
<filelist>
<file name="../bpel/myFile.bpel"/>
</filelist>
</bunit-instrument>
By default, a code coverage report is generated for activities. If you want to include links, add the optional <coverage> element.
- 3. In the target named test, uncomment the <engine properties> section.
- 4. In the target named coverage report, do the following:
- - Provide a destination directory for your report.
- - Provide a report type. The types are HTML (default), XML (raw XML used to create HTML) or CONSOLE (writes summary results to the Ant Logger that you specify on the command line)
- - If you create a HTML report, you can add an xsltPath attribute.
- - Rename the filePrefix, if desired. The Ant project name is the default filePrefix. When you generate a report, the date and time are appended to the prefix.
- 5. Run the B-unit ant script on the command line to generate the report. For example, in a command window, type ant -f filename.ant.xml.
What the Code Coverage Report Shows
- •Activity Coverage (default coverage): the total number of activities executed at least once over the total number of activities in the process.
- •Link Coverage (optional): the total number of activities that evaluated to true plus those that evaluated to false over the 2x total number of links with conditions.
(totalTrue + totalFalse) / (totalLinksWithConditions *2).
This ensures that the unit tests cover the execution of links completely because each link with a condition can evaluate to true or false.
Adding Code Coverage to an Existing B-Unit Ant Script
If you have an existing B-unit ant script, you can add code coverage to it just by putting in the correct ant tasks in the B-unit ant script.
- •Register the following typedefs in your Ant script and note that the attribute loaderref is set to bunit. This attribute must be set in order for all the Ant tasks to use the same classloader. The value of the attribute is unimportant as long as the value for all three typedefs match:
<typedef classname="com.activee.ant.bunit.tasks.AeBUnitTask"
loaderref="bunit" classpathref="bunit.classpath" name="bunit"/>
<typedef classname="com.activee.ant.bunit.coverage.AeBUnitInstrumentTask"
loaderref="bunit" classpathref="bunit.classpath" name="bunit-instrument"/>
<typedef classname="com.activee.ant.bunit.coverage.AeBUnitCoverageReportTask"
loaderref="bunit" classpathref="bunit.classpath" name="bunit-report"/>
- •Instrument your processes that are part of code coverage:
<bunit-instrument>
<coverage activitycoverage="true" linkcoverage="true" />
<filelist>
<file name="../bpel/myBEPL.bpel"/>
</filelist>
</bunit-instrument>
- •Add the following engine property to the B-unit task that will execute the B-unit tests as follows:
<bunit processLogging="urn:ae:full" trace="on">
<engineProperties>
<engineProperty name="CustomManagers/AeBUnitCoverageManager/Class"
value="com.activee.rt.bunit.coverage.AeBUnitCoverageManager"/>
</engineProperties>
<filelist>
<file name="CancelTO.bunit"/>
<file name="CreateTO.bunit"/>
<file name="SubmitPO_UNI.bunit"/>
<file name="SubmitUNIPO_AIFallOut.bunit"/>
</filelist>
</bunit>
- •Finally, you will need to output the report using the bunit-report Ant task:
<bunit-report reportType="HTML"
destdir="/Users/User1/Downloads/bunit/html" />
For details on the parameters you can use for the B-unit report task (filePrefix, xsltPath, destDir, and reportType, see Step Four in the above procedure.