JUnit Listener Configuration In Gradle

后端 未结 2 1074
孤城傲影
孤城傲影 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.

    0 讨论(0)
  • 2021-01-14 16:06

    I’m afraid, there is currently no support for JUnit RunListeners in Gradle. There is only an open ticket requesting that feature: https://github.com/gradle/gradle/issues/1330

    As someone has mentioned in the comments on that ticket, “the primary issue […] is the absence of TestDescriptor.getAnnotations()” in Gradle; otherwise you might have been able to rewrite your RunListener as a Gradle TestListener. So unless I’ve missed something when skimming through the ticket, it seems that you are mostly out of luck at the moment :-(

    0 讨论(0)
提交回复
热议问题