JUnit Listener Configuration In Gradle

后端 未结 2 1099
孤城傲影
孤城傲影 2021-01-14 15:42

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

2条回答
  •  庸人自扰
    2021-01-14 16:03

    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.

    Gradle Configuration for JUnit Foundation

    // 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.

提交回复
热议问题