TestNG

Getting started

There's a few things you should know when getting started running your tests using the TestNG framework on Testery. Since Java is a compiled language, Testery cannot pull your tests directly from your repository. You will need to upload a JAR file to Testery.

If using Gradle...

To see an example project using our Gradle plugin with TestNG you can look at our example-testng repository.

To use the plugin in your project you'll first have to add the Testery Gradle plugin to your build.gradle file:

plugins {
id 'io.testery' version '1.3'
}

Then configure the plugin file in your build.gradle file:

testery {
apiToken = System.getenv("TESTERY_API_TOKEN") // required
projectKey = "my-testery-project-key" // required
buildId = System.getenv("BUILD_ID") // required
commitHash = System.getenv("GIT_COMMIT") // optional
branch = System.getenv("GIT_BRANCH") // optional
}

Depending on your CI and environment, you might have to pull your apiToken buildId commitHash and branch from different variables.

You'll most likely have to configure an environment variable with your API token. The API token can be found in Testery on the Settings --> Integrations tab.

Once that is configured you can run this command: ./gradlew uploadBuildToTestery

If using Maven...

Create a fat JAR file

Testery will need a JAR file named testery.jar that contains all your test code and any dependencies that the tests depend on. It may be easiest to package up all source code, test code and all dependencies in one fat JAR file.

Add the following to your POM.xml file:

<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-assembly-plugin</artifactId>
<version>3.1.1</version>
<configuration>
<descriptorRefs>
<descriptorRef>jar-with-dependencies</descriptorRef>
</descriptorRefs>
<descriptors>
<descriptor>src/main/assembly/assembly.xml</descriptor>
</descriptors>
</configuration>
<executions>
<execution>
<id>make-assembly</id>
<phase>package</phase>
<goals>
<goal>single</goal>
</goals>
</execution>
</executions>
</plugin>

You will also need to create this assembly.xml file (replacing the path in your POM.xml file to the correct location in your project):

<assembly
xmlns="http://maven.apache.org/plugins/maven-assembly-plugin/assembly/1.1.3"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/plugins/maven-assembly-plugin/assembly/1.1.3 http://maven.apache.org/xsd/assembly-1.1.3.xsd">
<id>fat-tests</id>
<formats>
<format>jar</format>
</formats>
<includeBaseDirectory>false</includeBaseDirectory>
<dependencySets>
<dependencySet>
<outputDirectory>/</outputDirectory>
<useProjectArtifact>true</useProjectArtifact>
<unpack>true</unpack>
<scope>test</scope>
</dependencySet>
</dependencySets>
<fileSets>
<fileSet>
<directory>${project.build.directory}/test-classes</directory>
<outputDirectory>/</outputDirectory>
<includes>
<include>**/*.class</include>
</includes>
<useDefaultExcludes>true</useDefaultExcludes>
</fileSet>
</fileSets>
</assembly>

Now run this command: mvn clean compile test-compile assembly:single

Rename your JAR file to testery.jar before uploading to Testery.

Upload your testery.jar file to Testery

At this point you should have a fat JAR file named testery.jar that contains all your test code and required dependencies. Before uploading your JAR file to Testery make sure you have a project created in Testery to upload the JAR file to.

To upload your JAR using Testery CLI run this:

testery upload-build-artifacts --token {api-token} --project-key {project-key} --build-id {build-id} --path {directory_path}/testery.jar

The API token can be found in Testery on the Settings --> Integrations tab.

For more details on uploading artifacts using the Testery CLI see upload your JAR file to Testery using the Testery CLI.

Run your tests in Testery

Now that you've uploaded your JAR to Testery make sure your project settings are correct. Especially testing framework field (should be TestNG) and the Java package field. Once that those set you can run your tests. Go to the Test Runs tab and select New Test Run. At a minimum, select your project and build along with any other options you want and click Run Test

Running TestNG tests on Testery

There are a few things to note when running your tests on Testery.

  • Ignored tests will now show up in Testery

  • Testery does not currently support TestNG suites (although this is coming soon)

  • Testery handles parallelization of tests so any parallel parameters in your tests will be ignored