Running Tests (Only) using SeaLights Gradle plugin (JSON file)
Please make sure the Sealights Test Listener is deployed to capture coverage of the application to be tested by this script.
For Java application, you can refer to https://sealights.atlassian.net/wiki/spaces/SUP/pages/3473596
SeaLights build scanner (sl-build-scanner.jar) can be used to update build.gradle script with the settings and enable its execution during the relevant Gradle projects.
Configuration file
Create a JSON configuration file with the following parameters in order to provide the necessary configuration fields to the SeaLights Gradle plugin:
token or tokenFile - set with a token or a file containing the token obtained from the SeaLights dashboard
buildSessionId or buildSessionIdFile - Set with a build session id or a file containing the build session id created externally via the config step
createBuildSessionId - Set to false
executionType - set to testsonly to execute only the test listener. This will appear as
runTestOnly=true
in the integrated gradle file.
{
"executionType":"testsonly",
"tokenFile": "./sltoken.txt",
"createBuildSessionId": false,
"labId": "${System.getenv('LAB_ID')}",
"filesStorage":"/tmp",
"logEnabled":false,
"logLevel":"off",
"logToFile":false,
"logToConsole":true,
"proxy": null,
"runFunctionalTests": true,
"testTasksAndStages":{"test":"Functional Tests"},
"testListenerJvmParams":{"sl.tags":"cucumber"}
}
The following optional parameters:
logEnabled - Set to true if you want a log to be created
logLevel - Set the log level to create. For example WARN or INFO
logToFile - Set to true if you want the log to written to a file
logToConsole - Set to true if you want the log to written to the console
filesStorage - location of temporary folder location to store cached agent files
proxy - Provide the URL to the proxy to route the calls through if needed
labId - Unique ID for a set of test labs in case multiple labs are running simultaneously
runFunctionalTests - Set to true to enforce partial validation of build. This is commonly used when the tested application is for example an Integration Build or a different technology than Java. In these cases, the Java packages included parameter will not be validated.
testListenerJvmParams - Containing an array of all the parameters you want to pass to all the SeaLights test execution step, Note: the key and values must always be strings
testTasksAndStages - A map of tasks and their test stage names to integrate SeaLights into the
jvmargs
. Default aretest
,unitPlatformTest
with test stage "Unit Tests" andintegrationTest
with test stage "Integration Tests"
For additional parameters values and information, please refer to Gradle plugin Command reference - JSON Configuration file parameters
When using gradle on Windows, you will need to double the backslash used in path file for parameters like tokenFile, buildSessionIdFile and fileStorage - i.e. tokenFile = "C:\\Sealights\\sltoken.txt"
Integrating into the Build.gradle script
Before running your Gradle build, you run the build scanner with -gradle flag to integrate the SeaLights Gradle plugin into the build.gradle file. This will create a sealights.gradle script with all the configuration taken from the JSON config file and append a reference to it in build.gradle.
The standard parameters the build scanner receives are:
configfile - The path to the JSON configuration you created with the parameters to be provided to the SeaLights Gradle plugin
workspacepath - The base path to the location of the build.gradle file to update
java -jar sl-build-scanner.jar -gradle -configfile sl-config.json -workspacepath .
Executing your tests with Gradle
You can use your regular gradle command to execute your tests.
Typically the command is 'gradle clean test' for example.
Restoring the build.gradle file to its previous state
In case the project is to be restored to its previous state before the SeaLights plugin was applied, use the build scanner with the -restoreGradle
flag on the workspace where the gradle.build
file is located:
java -jar sl-build-scanner.jar -restoreGradle -workspacepath .
This command will (1) restore gradle.build from backup, (2) delete the backup file, and (3) delete the sealights.gradle file.
Failure at any of these steps won’t prevent the next ones, so that the project is restored as much as possible.