2016-01-22 170 views
3

我想运行一个junit4测试套件并在build.gradle中使用过滤器指定它,但gradle(版本2.10)未找到测试。 有没有办法在gradle中运行指定的junit测试套件?过滤junit测试套件时未找到测试

我的测试套件类

 

    @RunWith(Suite.class) 
    @SuiteClasses({ TestFoo.class, TestBar.class }) 
    public class MyTestSuite { 

    } 

的build.gradle

 

    test { 
     filter { 
      includeTestsMatching "*MyTestSuite" 
     } 
    } 

+0

同样的问题:https://stackoverflow.com/questions/46719406/gradle-test-task-does-not-run -junit-test-with-category-and-runwith-annotations – isobretatel

回答

1

DSL documentation的例子使用include代替:

test { 
    // explicitly include or exclude tests 
    include 'org/foo/**' 
    exclude 'org/boo/**' 
} 
+0

是的,包括作品。(在我的情况下,通过添加包含'**/MyTestSuite.class'的行)过滤器不适用于junit测试套件? –

0

滤波器大概意思在组合使用包括和排除。 Doc说:允许过滤执行测试

所以,如果你想运行只是一个单一的方法foo:

test { 
    include '**MyTestSuite.class' 
    filter { 
      includeTestsMatching "*TestBar.foo" 
    } 
}