Java Gradle测试任务不使用@Category和@RunWith注释运行JUnit测试
Gradle不使用@Category和@RunWith注释运行我的JUnit测试 Java8,Gradle4.2.1 我的JUnit课程:Java Gradle测试任务不使用@Category和@RunWith注释运行JUnit测试,java,gradle,junit,Java,Gradle,Junit,Gradle不使用@Category和@RunWith注释运行我的JUnit测试 Java8,Gradle4.2.1 我的JUnit课程: public interface FastTest { } @Category(FastTest.class) @RunWith(PowerMockRunner.class) public class MyTest { @Test public void testMyMethod() { // Test method sho
public interface FastTest {
}
@Category(FastTest.class)
@RunWith(PowerMockRunner.class)
public class MyTest {
@Test
public void testMyMethod() {
// Test method should fail
assertTrue(false);
}
}
@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);
}
}
我的身材。格雷德尔:
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设置无效。报告的渐变问题:
PowerMock使用代理替换类别批注:
解决方法:将PowerMockIgnore注释添加到JUnit类:
public interface FastTest {
}
@Category(FastTest.class)
@RunWith(PowerMockRunner.class)
public class MyTest {
@Test
public void testMyMethod() {
// Test method should fail
assertTrue(false);
}
}
@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);
}
}
不。它必须是Gradle。看起来PowerMock用代理替换了@Category注释:谢谢,刚刚遇到了同样的问题。值得注意的是,“FastTest”也需要是完全限定的包/类名,就像“Category”是完全限定的一样。