Unit Test Code Coverage
Unit test coverage in Message Broker works similarly to what developers are used to in other languages such as Java.
It can most easily compared to cobertura, where the initial code is packaged up as a BAR file, that BAR file is then instrumented with additional ESQL, Java and XSL calls.
Currently we support test coverage for:
- ESQL
- Msgflows
- XSL (within WMB/IIB)
- Java
The instrumented BAR file is deployed to a running environment, and then the test cases are run.
The results are processed into a SonarQube standard file called “Coverage.xml”, which can then be used as part of the Sonar analysis to report code coverage metrics.
From those metrics quality gates can be built as part of a continuous integration/deployment process.
Setup files
The files needed to run the coverage reporting can be found here.
You will also need the latest MB-Precise.jar file as well.
An example ANT script might look like the following
<?xml version=”1.0″?> <project name=”project” default=”run”><!– We have made changes to the way that the instrumentation is done so that you no longer need any external dependencies to make use of the instrumented bar file /> –><!– to access the coverage report when running sonar you need to configure the location in the sonar-project.properties file # coverage sonar.genericcoverage.reportPaths=/coveragetemp/coverage.xml –> <property name=”IIB.CREATEBAR” value=”C:/Program Files/IBM/IIB/10.0.0.1/server/bin” /> <property name=”IIB.EG” value=”CN_EG1″ /> <target name=”init” description=”"> <!– the required jars to run the instrumentation and recording process –> <!– setup ant tasks required –> <typedef name=”listener” <typedef name=”stopper” <!– this could be any task that can trigger the test to start such as calling a url, sending an MQ message to SOAP <property environment=”env” /> <!– need to clean bars directry –> </target> <target name=”run” description=”" depends=”init”> <!– build the bar as your normally would –> <!– this task unpacks the bar, updates the esql and repacks the bar –> <!– deploy the “instrumented” bar file –> <!– start the results listener and then run the tests –> <!– this stops the listener if it hasn’t finished already and forces the results to be recorded –> </target> <target name=”mqsicreatebar.buildbar”> <echo message=”============= mqsicreatebar =====================” /> <exec executable=”${IIB.CREATEBAR_TOOLS}/mqsicreatebar” spawn=”false” failonerror=”true”> <echo message=”(Using mqsicreatebar) Completed building Broker Archive file – ${APP.NAME}-${BUILD.NUMBER}.bar ” /> <target name=”instrument.bar” > <echo message=”==================================================” /> <instrument barFileName=”bars\Coverage1-0.01.bar” coverageFilePath=”coveragetemp” address=”machinenamerunninglistener” port=”9011″ /> <target name=”mqsideploybar” > <property environment=”env”/> <echo message=”==============================================” /> <echo message=”Deploying Broker Archive file: ${APP.NAME}-${BUILD.NUMBER}.bar ” /> <java classname=”com.ibm.broker.config.util.Deploy” failonerror=”true” fork=”true”> <echo message=”Completed deploying Broker Archive file – ${BARDIR}\${APP.NAME}-${BUILD.NUMBER}-instrumented.bar” /> <target name=”runtests” > </project> |