2017-10-12 7 views
2

@Categoryと@RunWithアノテーションでJUnitテストを実行しません。@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); 
    } 
} 

私のbuild.gradle:私はRunWithアノテーションを削除した場合

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' } 
} 

、Gradleのは、テストを実行します。 scanForTestClasses = falseの設定は無効です。

+0

号。 – isobretatel

+0

PowerMockは@Categoryアノテーションをプロキシで置き換えるようです:https://stackoverflow.com/questions/13377634/runwithpowermockrunner-class-does-not-work-with-package-annotation?rq=1 – isobretatel

答えて

3

報告されているGradleの問題:https://github.com/gradle/gradle/issues/3189

PowerMockは、プロキシとカテゴリー注釈を置き換えます。RunWith(PowerMockRunner.class) does not work with package annotation

回避策:JUnitのクラスにPowerMockIgnoreアノテーションを追加します。それはGradleのでなければなら

@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); 
    } 
} 
+1

ありがとう、ちょうどこの同じ問題に遭遇しました。 「FastTest」は、「カテゴリ」が完全修飾されているのと同じように、完全修飾パッケージ/クラス名である必要があります。 – doeiqts

関連する問題