Gradle中的JUnit侦听器配置
我是格拉德尔的新人。拥有自定义JUnit侦听器,它读取自定义注释数据并生成报告,需要将其配置为Gradle的一部分。Gradle 4.4中的surefire插件是否需要配置Gradle中的JUnit侦听器配置,gradle,junit,maven-surefire-plugin,Gradle,Junit,Maven Surefire Plugin,我是格拉德尔的新人。拥有自定义JUnit侦听器,它读取自定义注释数据并生成报告,需要将其配置为Gradle的一部分。Gradle 4.4中的surefire插件是否需要配置 <plugin> <groupId>org.apache.maven.plugins</groupId> <artifactId>maven-surefire-plugin</artifactId> <version>2.18.1
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<version>2.18.1</version>
<configuration>
<properties>
<property>
<name>listener</name>
<value>my.company.MyRunListener</value>
</property>
</properties>
</configuration>
</plugin>
org.apache.maven.plugins
,它不支持读取注释以继续执行该操作
我想了解在Gradle中配置JUnit侦听器的方法。恐怕,目前不支持在Gradle中配置JUnit侦听器。只有一个打开的票证请求该功能:
正如有人在该票据上所说,“主要问题[…]是Gradle中缺少TestDescriptor.getAnnotations()
”;否则,您可能已经能够将RunListener
重写为GradleTestListener
。因此,除非我在浏览票证时遗漏了什么,否则您目前似乎运气不佳:-(该库允许您在服务提供商配置文件中声明侦听器,然后自动附加该文件,而不管执行环境如何。可以找到详细信息
JUnit地基的级配配置
ServiceLoader
提供程序配置文件
通过此配置,MyRunListener
实现的侦听器将自动连接到提供给运行()的运行通知程序
JUnit运行程序的方法。此功能消除了各种测试执行环境(如Maven、Gradle和本机IDE测试运行程序)之间的行为差异。谢谢。@Chriki,根据链接,Gradle中不支持JUnit侦听器。Tbink Gradle团队可以在其测试环境中解决所有类型的需求如果团队已经决定不支持JUnit侦听器。让我用BEEV建议的方式试试,@ SKC:听起来不错,我很乐意阅读你在这里的实验结果。如果你发现我的答案有用,那么请考虑投票:@skc:JUnit Foundation的library使您能够通过ServiceLoader
附加JUnit4RunListener
类,就像JUnit5一样。有关详细信息,请参见下面的答案。
// 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
}
# src/main/resources/META-INF/services/com.nordstrom.automation.junit.JUnitWatcher
com.example.MyRunListener