Gradle 不使用 @Category 和 @RunWith 注释运行我的 JUnit 测试。
Java 8,Gradle 4.2.1。
我的 JUnit 类:
public interface FastTest {
}
@Category(FastTest.class)
@RunWith(PowerMockRunner.class)
public class MyTest {
@Test
public void testMyMethod() {
// Test method should fail
assertTrue(false);
}
}
我的构建.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' }
}
如果我删除 RunWith 注释,Gradle 会运行测试。
scanForTestClasses = false 设置无效。
报告的 Gradle 问题:https://github.com/gradle/gradle/issues/3189 https://github.com/gradle/gradle/issues/3189.
PowerMock 用代理替换类别注释:RunWith(PowerMockRunner.class) 不适用于包注释 https://stackoverflow.com/questions/13377634/
解决方法:将 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);
}
}
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)