# Running Tests

Gathering coverage and test information using the SeaLights Java Test Listener is done in a few steps. Use the Lab ID to connect between the test listener and the application under test.

## Working with a supported framework <a href="#working-with-a-supported-framework" id="working-with-a-supported-framework"></a>

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.

{% code overflow="wrap" lineNumbers="true" %}

```bash
export SEALIGHTS_OPTS="-javaagent:/path/to/sl-test-listener.jar -Dsl.tags=testNG -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
```

{% endcode %}

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.

{% hint style="info" %}
See [Command Reference](/knowledgebase/setup-and-configuration/sealights-agents-and-plugins/java-agent/command-reference.md#installing-test-listener-as-java-agent) for full parameter details.
{% endhint %}

## Working without a supported framework <a href="#working-without-a-supported-framework" id="working-without-a-supported-framework"></a>

### Starting the Test Stage <a href="#starting-the-test-stage" id="starting-the-test-stage"></a>

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

{% code overflow="wrap" lineNumbers="true" %}

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

{% endcode %}

{% hint style="info" %}
See [Command Reference](/knowledgebase/setup-and-configuration/sealights-agents-and-plugins/java-agent/command-reference.md#inlineextension-starting-a-test-stage) for full parameter details
{% endhint %}

### Running your tests <a href="#running-your-tests" id="running-your-tests"></a>

#### Functional Tests <a href="#functional-tests" id="functional-tests"></a>

* Before running your functional tests you need to set up the backend server to receive the test footprints. See [Command Reference](/knowledgebase/setup-and-configuration/sealights-agents-and-plugins/java-agent/command-reference.md#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 <a href="#unit-tests" id="unit-tests"></a>

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 [Command Reference](/knowledgebase/setup-and-configuration/sealights-agents-and-plugins/java-agent/command-reference.md#installing-test-listener-as-java-agent)

### Upload report files <a href="#upload-report-files" id="upload-report-files"></a>

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

{% code overflow="wrap" lineNumbers="true" %}

```java
java -jar sl-test-listener.jar uploadReports -tokenfile /path/to/sltoken.txt -labid <Lab ID> -reportFile "/path/to/junit_report.xml" -source "Junit xml report"
```

{% endcode %}

{% hint style="warning" %}
This command **must be** executed while your **Test Stage is still open** (a.k.a. before the `end` command), otherwise the report information won't be visible and associated with it in your dashboard.
{% endhint %}

{% hint style="info" %}

* See [Broken mention](broken://pages/PQsT2u0e0LX34lONSK2b) for information on how to upload multiple files
* See [Command Reference](/knowledgebase/setup-and-configuration/sealights-agents-and-plugins/java-agent/command-reference.md#inlineextension-upload-report-files) for full parameter details
  {% endhint %}

### Ending the Test Stage <a href="#ending-the-test-stage" id="ending-the-test-stage"></a>

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

{% code overflow="wrap" lineNumbers="true" %}

```java
java -jar sl-test-listener.jar end -tokenfile /path/to/sltoken.txt -labid <Lab ID>
```

{% endcode %}

{% hint style="info" %}
See [Command Reference](/knowledgebase/setup-and-configuration/sealights-agents-and-plugins/java-agent/command-reference.md#inlineextension-ending-a-test-stage) for full parameter details
{% endhint %}


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://docs.sealights.io/knowledgebase/setup-and-configuration/sealights-agents-and-plugins/java-agent/default-usage-cli/running-tests.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
