Cannot include/exclude Junit tests classes by Category using gradle

有些话、适合烂在心里 提交于 2019-12-02 02:17:34

问题


Given these interfaces

testclient.priority.High
testclient.priority.Low

and a junit classes annotated like this

@Category(testclient.priority.High.class)
public class MyTest {
...
}
@Category(testclient.priority.Low.class)
public class MyOtherTest {
...
}

I tried to configure an include/exclude pattern in build.gradle like this

useJUnit {
    includeCategories 'testclient.priority.High'
    excludeCategories 'testclient.priority.Low'
}

The problem is that no tests are run, at all. How is the exact syntax to achieve that? I am using gradle 2.14.1 and invoke the tests by "clean build".


回答1:


This works for me with Gradle 2.12. I don't know what is different between our respective environments, but I have placed my solution on GitHub for reference.

Note that I have placed FastTest.java and SlowTest.java in the src/test/java/net/codetojoy folder, where the tests reside.




回答2:


I found the problem myself. I missed the fact that

High extends Low

so the exclusion correctly affected all annotated tests. The extension is intended and the correct pattern in build.gradle would simply be:

useJUnit {
    includeCategories 'testclient.priority.High'
}

In fact there are five priority levels and the extension dependency is an easy way to configure something like "run everything of this level or higher".



来源:https://stackoverflow.com/questions/38872369/cannot-include-exclude-junit-tests-classes-by-category-using-gradle

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!