ANT build tool
Creating a Session ID
Before running the build scan and tests, you need to create a session ID. The session ID is provided to each step in order to link them together as one complete cycle.
Generating a session ID in Java is done using the Java Build scanner with the -config flag. This command can be executed as an ANT Java task.
<tstamp>
<format property="time.stamp" pattern="yyyyMMdd-HHmm"/>
</tstamp>
<target name="sealights_config">
<java jar="${sealights.dir}/sl-build-scanner.jar" fork="true">
<arg value="-config"/>
<arg value="-tokenfile"/>
<arg value="${sealights.dir}/sltoken.txt"/>
<arg value="-appname"/>
<arg value="myApp"/>
<arg value="-branchname"/>
<arg value="master"/>
<arg value="-buildname"/>
<arg value="${time.stamp}"/>
<arg value="-pi"/>
<arg value="*com.company.*"/>
</java>
</target>In the sample code above, we have used a timestamp for the build name but any environment variable can be used according to your organization’s naming convention.
Scanning a build
In order to collect coverage information SeaLights, agents need to first scan the binary files for the build information: it can be the *.class, *.jar, or even the *.war files.
Scanning a build in ANT is achieved using the Java Build scanner executed as an ANT Java task.
In order to add logs flags, you need to add the
<jvmarg>values like below<jvmarg value="-Dsl.log.toConsole=true"/><jvmarg value="-Dsl.log.level=info"/>
Running tests using JUnit
In order to capture code coverage information from tests run with JUnit, you need to run it with our test listener as a Java agent.
JUnit 4.x
The listener needs to be passed using the
jvmargattribute-javaagentparameter together with its required parameters.
JUnit 5.x
When tests are running in the same process, the listener needs to be passed using the
jvmargattribute-javaagentparameter with Sealights' Anonymous Execution mode deactivated.When tests are running in a different process (via a fork), we need to add the
startandendcommands before and after tests execution
Sample integration into an existing ANT project
In order to keep backward compatibility, you can use the ant:if condition to execute Sealights commands according to a boolean.
In the sample below, you’ll be required to add -Dsealights=true to your ANT command in order to enable the agents.
Here is a comparison of executions with and without the sealigths parameter set to true.

Last updated
Was this helpful?

