Table of Contents |
---|
...
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.
In the following sample, we have used a timestamp for the build name but any environment variable can be used according to your organization’s naming convention.
Code Block | ||
---|---|---|
| ||
<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="/path/to${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.
Info |
---|
See 'Java Command Reference - Creating a session ID' for full parameter details |
...
Code Block | ||
---|---|---|
| ||
<target name="sealights_scan" depends="compile,sealights_config"> <java jar="${sealights.dir}/sl-build-scanner.jar" fork="true"> <arg value="-scan"/> <arg value="-tokenfile"/> <arg value="/path/to${sealights.dir}/sltoken.txt"/> <arg value="-buildsessionidfile"/> <arg value="buildSessionId.txt"/> <arg value="-workspacepath"/> <arg value="${build}"/> <arg value="-r"/> <arg value="-fi"/> <arg value="*.class"/> </java> </target> |
...
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
jvmarg
attribute-javaagent
parameter together with its required parameters.
Code Block | ||
---|---|---|
| ||
<junit fork="yes"> <jvmarg value="-javaagent:${sealights.dir}/sl-test-listener.jar"/> <jvmarg value="-Dsl.tokenFile=${sealights.dir}/sltoken.txt"/> <jvmarg value="-Dsl.buildSessionIdFile=/path/to/sltokenbuildSessionId.txt"/> <jvmarg value="-Dsl.testStage=Unit Tests"/> </junit> |
JUnit 5.x
When tests are running in the same process, the listener needs to be passed using the
jvmarg
attribute-javaagent
parameter with Sealights' Anonymous Execution mode deactivated.When tests are running in a different process (via a fork), we need to add the
start
andend
commands before and after tests execution
Same process (not forked) | Different process (forked) | ||||
---|---|---|---|---|---|
|
...
|
|
...
|
...
|
Info |
---|
See 'Java Command Reference - Installing test listener as Java Agent' for full parameter details |
Sample integration into an existing ANT project
...
Here is a comparison of executions with and without the sealigths
parameter set to true
.
...