I\'m new bee to Gradle. Have custom JUnit Listener, which reads the custom annotation data and generates report and need to configure it as part of Gradle. Is there anyway t
The JUnit Foundation library enables you to declare your listeners in a service provider configuration file, which are then attached automatically - regardless of execution environment. Details can be found here.
// build.gradle
...
apply plugin: 'maven'
sourceCompatibility = 1.8
targetCompatibility = 1.8
repositories {
mavenLocal()
mavenCentral()
...
}
dependencies {
...
compile 'com.nordstrom.tools:junit-foundation:12.2.0'
}
ext {
junitFoundation = configurations.compile.resolvedConfiguration.resolvedArtifacts.find { it.name == 'junit-foundation' }
}
test.doFirst {
jvmArgs "-javaagent:${junitFoundation.file}"
}
test {
// debug true
// not required, but definitely useful
testLogging.showStandardStreams = true
}
ServiceLoader provider configuration file# src/main/resources/META-INF/services/com.nordstrom.automation.junit.JUnitWatcher
com.example.MyRunListener
With this configuration, the listener implemented by MyRunListener will be automatically attached to the RunNotifier supplied to the run() method of JUnit runners. This feature eliminates behavioral differences between the various test execution environments like Maven, Gradle, and native IDE test runners.