[英]Gradle test task does not run JUnit test with @Category and @RunWith annotations
Gradle does not run my JUnit test with @Category and @RunWith annotations. Gradle没有使用@Category和@RunWith注释运行我的JUnit测试。
Java 8, Gradle 4.2.1. Java 8,Gradle 4.2.1。
My JUnit class: 我的JUnit类:
public interface FastTest {
}
@Category(FastTest.class)
@RunWith(PowerMockRunner.class)
public class MyTest {
@Test
public void testMyMethod() {
// Test method should fail
assertTrue(false);
}
}
My build.gradle: 我的build.gradle:
apply plugin: 'java'
repositories { mavenCentral() }
dependencies {
compile "junit:junit:4.12"
compile "org.powermock:powermock-core:1.6.5"
compile "org.powermock:powermock-api-mockito-common:1.6.5"
compile "org.powermock:powermock-module-junit4:1.6.5"
compile "org.powermock:powermock-api-mockito:1.6.5"
}
test {
scanForTestClasses = false
useJUnit { includeCategories 'FastTest' }
}
If I remove RunWith annotation, Gradle runs the test. 如果我删除RunWith注释,Gradle将运行测试。 The scanForTestClasses = false setting has no effect. scanForTestClasses = false设置无效。
Reported Gradle issue: https://github.com/gradle/gradle/issues/3189 . 报告的Gradle问题: https : //github.com/gradle/gradle/issues/3189 。
PowerMock replaces Category annotation with a proxy: RunWith(PowerMockRunner.class) does not work with package annotation PowerMock用代理替换Category注释: RunWith(PowerMockRunner.class)不适用于包注释
Workaround: Add PowerMockIgnore annotation to JUnit class: 解决方法:将PowerMockIgnore注释添加到JUnit类:
@PowerMockIgnore({ "org.junit.experimental.categories.Category", "mypackage.FastTest" })
@Category(FastTest.class)
@RunWith(PowerMockRunner.class)
public class MyTest {
@Test
public void testMyMethod() {
// Test method should fail
assertTrue(false);
}
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.