Gradle - Running Tests using Sealights plugin
When executing Tests via Gradle against a build already reported to Sealights, you have to provide the buildSessionId generated in a previous step via an environment variable or a text 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 Using Java Agents - Installing the Coverage Listener as a JVM Java Agent
In order to use Sealights Gradle plugin, you’ll need to update your build.gradle file with relevant settings and enable its execution during the relevant Gradle projects.
For example, by adding the -Psealights property to your Gradle command.
Configuring Gradle plugin in build.gradle
In the ‘repositories > dependencies’ section add:
classpath 'io.sealights.on-premise.agents.plugin:sealights-gradle-plugin:latest.release'
In the ‘allprojects’ section add the following:
apply plugin: 'io.sealights.on-premise.agents.plugin.sealights-gradle-plugin'
sealights section with the following parameters
token or tokenFile - set with a token or a file containing the token obtained from the SeaLights Settings page
buildSessionId or buildSessionIdFile - Set with a build session id or a file containing the build session id created externally via the config step unless you are using the labId to recieve the session ID
labId - Set the lab ID of the environment being tested (if not provided, it will be set to the session ID)
createBuildSessionId - Set to false
runTestOnly - Set to true if you want to only run tests without scanning builds
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
testListenerJvmParams - Containing and 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 in. Default are test, unitPlatformTest with test stage "Unit Tests" and integrationTest with test stage "Integration Tests"
In the following example, the steps needed are surrounded by an if condition which allows you to only use Sealights when you pass the -Psealights property when executing your gradle command.
Without this condition and property, Sealights integration will always be applied and used.
For additional parameters values and informaiton, please refer to Java Command Reference - Installing test listener as Java Agent
buildscript {
repositories {
mavenCentral()
dependencies {
if(project.hasProperty('sealights')){
classpath 'io.sealights.on-premise.agents.plugin:sealights-gradle-plugin:latest.release'
}
}
}
}
allprojects { p ->
if(project.hasProperty('sealights')){
apply plugin: 'io.sealights.on-premise.agents.plugin.sealights-gradle-plugin'
sealights {
tokenFile = "./sltoken.txt"
createBuildSessionId = false
buildSessionIdFile = "./buildSessionId.txt"
// buildSessionId = System.getenv('SL_BUILD_SESSION_ID')
// labId = "myLabId"
filesStorage="/tmp"
logEnabled = false
logLevel = "WARN"
logToFile = false
logToConsole = true
runTestOnly=true
testTasksAndStages=["test":"Functional Tests"]
// proxy = "http://localhost:8888"
// testListenerJvmParams=["sl.param1":"true","sl.param2":"value"]
}
}
} |
---|