Message Broker Test Coverage

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.

Coverage includes







All message flows executed (view able in the coverage report in Sonar or in the generated flow diagrams)

Coverage example

Coverage xsl example

Coverage example

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 file
# coverage

<property name=”IIB.CREATEBAR” value=”C:/Program Files/IBM/IIB/” />
<property name=”IIB.DEPLOYBAR” value=”C:/Program Files/IBM/IIB/” />
<property name=”IIB.CREATEBAR_TOOLS” value=”C:/Program Files/IBM/IIB/” />

<property name=”IIB.EG” value=”CN_EG1″ />
<property name=”IIB.RUNTIME” value=”CoverageNode” />
<property name=”BUILD.NUMBER” value=”0.01″ />
<property name=”BARDIR” value=”bars” />
<property name=”APP.NAME” value=”Coverage1″ />

<target name=”init” description=”">

<!– the required jars to run the instrumentation and recording process –>
<path id=”project.classpath”>
<!– this could refer to the Sonar extensions directory –>
<pathelement location=”C:\utils\bct\MB-precise-sonarplugin-2.28.jar”/>
<pathelement location=”C:\utils\bct\commons-io-2.0.1.jar”/>
<pathelement location=”C:\utils\bct\slf4j-api-1.7.5.jar”/>
<pathelement location=”C:\utils\bct\slf4j-jdk14-1.7.7.jar”/>
<pathelement location=”C:\utils\bct\commons-lang-2.6.jar”/>
<pathelement location=”C:\utils\bct\xstream-1.4.7.jar”/>
<pathelement location=”C:\utils\bct\plexus-utils-3.0.21.jar”/>
<pathelement location=”C:\utils\bct\xmlpull-”/>
<pathelement location=”C:\utils\bct\xpp3-”/>

<!– setup ant tasks required –>
<typedef name=”instrument”
classname=”” >
<classpath refid=”project.classpath” />

<typedef name=”listener”
classname=”” >
<classpath refid=”project.classpath” />

<typedef name=”stopper”
classname=”” >
<classpath refid=”project.classpath” />

<!– this could be any task that can trigger the test to start such as calling a url, sending an MQ message to SOAP
the urlTest just sends some text to a HttpRequest noode which triggers our example test. –>
<typedef name=”urlTest”
classname=”” >
<classpath refid=”project.classpath” />

<property environment=”env” />

<!– need to clean bars directry –>
<delete dir=”${BARDIR}”/>


<target name=”run” description=”" depends=”init”>

<!– build the bar as your normally would –>
<antcall target=”mqsicreatebar.buildbar” />

<!– this task unpacks the bar, updates the esql and repacks the bar –>
<antcall target=”” />

<!– deploy the “instrumented” bar file –>
<antcall target=”mqsideploybar” />

<!– start the results listener and then run the tests –>
<listener port=”9011″ maxWait=”30″ coverageFilePath=”coveragetemp”  />
<antcall target=”runtests” />

<!– this stops the listener if it hasn’t finished already and forces the results to be recorded –>
<stopper />


<target name=”mqsicreatebar.buildbar”>
<echo message=”(Using mqsicreatebar) building Broker Archive file: ${APP.NAME}-${BUILD.NUMBER}.bar ” />

<echo message=”============= mqsicreatebar =====================” />
<echo message=”${IIB.CREATEBAR_TOOLS}/mqsicreatebar -skipWSErrorCheck -cleanBuild -deployAsSource -data coverage_ws -b ${BARDIR}\${APP.NAME}-${BUILD.NUMBER}.bar -p Coverage1 -o Coverage1/Test1.msgflow -trace -v trace.log ” />
<echo message=”============= mqsicreatebar =====================” />

<exec executable=”${IIB.CREATEBAR_TOOLS}/mqsicreatebar” spawn=”false” failonerror=”true”>
<arg value=”-skipWSErrorCheck” />
<arg value=”-clean” />
<arg value=”-cleanBuild” />
<arg value=”-deployAsSource” />
<arg value=”-data” />
<arg value=”coverage_ws” />
<arg value=”-b” />
<arg value=”${BARDIR}\${APP.NAME}-${BUILD.NUMBER}.bar” />
<arg value=”-p” />
<arg value=”Coverage1″ />
<arg value=”-o” />
<arg value=”Coverage1/Test1.msgflow” />
<arg value=”Coverage1/Backlog2ShouldHaveReply.msgflow” />
<arg value=”-trace” />
<arg value=”-v” />
<arg value=”trace.log” />

<echo message=”(Using mqsicreatebar) Completed building Broker Archive file – ${APP.NAME}-${BUILD.NUMBER}.bar ” />

<target name=”” >
<echo message=”Instrumenting bar file ” />

<echo message=”==================================================” />
<echo message=”instrument ${BARDIR}\${APP.NAME}-${BUILD.NUMBER}.bar” />
<echo message=”==================================================” />

<instrument barFileName=”bars\” coverageFilePath=”coveragetemp” address=”machinenamerunninglistener” port=”9011″ />

<target name=”mqsideploybar” >

<property environment=”env”/>

<echo message=”==============================================” />
<echo message=”MQSI_WORKPATH = ${env.MQSI_WORKPATH}” />
<echo message=”==============================================” />

<echo message=”Deploying Broker Archive file: ${APP.NAME}-${BUILD.NUMBER}.bar ” />

<java classname=”” failonerror=”true” fork=”true”>
<arg value=”${IIB.RUNTIME}” />
<arg value=”-e” />
<arg value=”${IIB.EG}” />
<arg value=”-a” />
<arg value=”${BARDIR}\${APP.NAME}-${BUILD.NUMBER}” />
<fileset dir=”C:/Program Files/IBM/IIB/″>
<include name=”**/*.jar”/>

<echo message=”Completed deploying Broker Archive file – ${BARDIR}\${APP.NAME}-${BUILD.NUMBER}” />

<target name=”runtests” >
<!– HttpTestTask –>
<echo message=”Running test: http://localhost:7800/Test1″ />
<urlTest url=”http://localhost:7800/Test1″ />
<echo message=”Running test: http://localhost:7800/Test1 done” />