Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.
Table of Contents

...

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.

...

JUnit 4.x

...

JUnit 5.x

Code Block
languagexml
<junit fork="yes">
  <jvmarg value="-javaagent:${sealights.dir}/sl-test-listener.jar"/>
  <jvmarg value="-Dsl.tokenFile=${sealights.dir}/sltoken.txt"/>
  <jvmarg value="-Dsl.buildSessionIdFile=buildSessionId.txt"/>
  <jvmarg value="-Dsl.testStage=Unit Tests"/>
</junit>

JUnit 5.x

  1. 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.

  2. When tests are running in a different process (via a fork), we need to add the start and end commands before and after tests execution

Same process (not forked)

Different process (forked)

Code Block
languagexml
<junitlauncher>
	<testclasses outputdir="build/test-report">
		<jvmarg value="-javaagent:${sealights.dir}/sl-test-listener.jar"/>
		<jvmarg value="-Dsl.tokenFile=${sealights.dir}/sltoken.txt"/>
		<jvmarg value="-Dsl.buildSessionIdFile=buildSessionId.txt"/>
		<jvmarg value="-Dsl.anonymousExecution=false"/>
		<jvmarg value="-Dsl.testStage=Unit Tests"/>
	</testclasses>
	...
</junitlauncher>
Code Block
languagexml
<target name="test.junit.launcher" depends="compile">
<fork>
	<java jar="${sealights.dir}/sl--test-listener.jar" fork="true">
		<arg value="start"/>
		<arg value="-tokenfile"/>
		<arg value="${sealights.dir}/sltoken.txt"/>
		<arg value="-buildsessionidfile"/>
		<arg value="buildSessionId.txt"/>
		<arg value="-testStage"/>
		<arg value="Unit Tests"/>
	</java>
	<junitlauncher haltOnFailure="true" printSummary="true">
		<classpath refid="test.classpath"/>
		<testclasses outputdir="build/test-report">
			<fork>
				<jvmarg value="-javaagent:${sealights.dir}/sl--test-listener.jar"/>
				<jvmarg value="-Dsl.tokenFile=${sealights.dir}/sltoken.txt"/>
				<jvmarg value="-Dsl.buildSessionIdFile=buildSessionId.txt"/>
				<jvmarg value="-Dsl.testStage=Unit Tests"/>
			</fork>
		</testclasses>
	</junitlauncher>
	<java jar="${sealights.dir}/sl--test-listener.jar" fork="true">
		<arg value="end"/>
		<arg value="-tokenfile"/>
		<arg value="${sealights.dir}/sltoken.txt"/>
		<arg value="-buildsessionidfile"/>
		<arg value="buildSessionId.txt"/>
	</
fork> ... </junitlauncher>
java>
</target>
Info

See 'Java Command Reference - Installing test listener as Java Agent' for full parameter details

Sample integration into an existing ANT project

...