Using Java Agents - Running Tests

Gathering coverage and test information using the SeaLights Java Test Listener is done in a few steps, we recommend to use the Lab ID for this. If your component does not yet support the Lab ID option, use the Build Session ID to connect between the test listener and the test runner

Working with a supported framework

When working with a supported framework - for example, JUnit or TestNG - you can add the Sealights test listener as a Java agent that automatically captures the test information.

export SEALIGHTS_OPTS="-javaagent:/path/to/sl-test-listener.jar -Dsl.tags=testNG -tokenfile -Dsl.tokenFile=/path/to/sltoken.txt -Dsl.labid <Lab ID> -Dsl.testStage \"Functional Tests\" " java $SEALIGHTS_OPTS -cp <CLASSPATH> org.testng.TestNG -testclass com.my.test

In the sample command above, the javaagent is declared via a dedicated SEALIGHTS_OPTS environment variable, but you can also declare it via standard JVM variables, like JAVA_OPTS or JAVA_TOOL_OPTIONS for example. This is useful for testing frameworks like Cucumber for Java, which relies on JUnit or TestNG behind the scenes.

If the BuildSessionId needs to be passed explicitly, you should use a command similar to the one below

export SEALIGHTS_OPTS="-javaagent:/path/to/sl-test-listener.jar -Dsl.tags=testNG -tokenfile -Dsl.tokenFile=/path/to/sltoken.txt -Dsl.buildSessionIdFile=buildSessionId.txt -Dsl.labid <Lab ID> -Dsl.testStage \"Functional Tests\" " java $SEALIGHTS_OPTS -cp <CLASSPATH> org.testng.TestNG -testclass com.my.test

Working without a supported framework

Starting the Test Stage

First the SeaLights server needs to be notified that a test stage is starting.

java -jar sl-test-listener.jar start -tokenfile /path/to/sltoken.txt -labid <Lab ID> -testStage "Functional Tests"

See 'Java Command Reference - Starting a test stage' for full parameter details

Running your tests

Functional Tests

Before running your functional tests you need to set up the backend server to receive the test footprints. See 'Using Java Agents - Installing Test Listener as Java Agent'

Once set up you now run your tests normally while generating one or more JUnit xml result files to be reported to the SeaLights server.

Unit Tests

As the unit tests are not run against a backend server, you need to run the actual tests using the Sealights Java Agent while generating one or more JUnit xml result files to be reported to the SeaLights server.

The command is the same as you would use on the backend server. See 'Using Java Agents - Installing Test Listener as Java Agent'

Upload report files

Once done running the tests you upload the report files to the SeaLights server

Ending the Test Stage

The server needs to be notified that a test stage has ended.