How to include multiple categories in junit4?

点点圈 提交于 2019-12-11 07:27:09

问题


I want to include multiple categories for a junit runner.

Java Code

@RunWith(Categories.class)
@IncludeCategory(IMAP.class , POP.class)
@SuiteClasses({MailTestSuites.class})
public class TestSuiteRunner{

}

I want to run my test suite for these two categories only. I have categories for mail suite like "IMAP,POP , SMTP , POP3". Now , I want to run only "IMAP , POP" category suites only. How can I run with junit?


回答1:


Up to version JUnit 4.11, @IncludeCategory and @ExcludeCategory only support one value. However, starting with the upcoming release 4.12, it will be allowed to pass multiple values.

According to the documentation in the source code, you can then write:

@RunWith(Categories.class)
@IncludeCategory({IMAP.class, POP.class})
@SuiteClasses({MailTestSuites.class})



回答2:


No, you couldn't define multiple values of @IncludeCategory in one Categories.

I recommend you use multiple Categories to run your test cases. (Separate IMAP and POP test cases)

//IMAP tests
@RunWith(Categories.class)
@IncludeCategory(IMAP.class)
@SuiteClasses({MailTestSuites1.class})
public class TestSuiteRunner1{}

//POP tests
@RunWith(Categories.class)
@IncludeCategory(POP.class)
@SuiteClasses({MailTestSuites2.class})
public class TestSuiteRunner2{}

//Merge into one Test
@RunWith(Suite.class)
@Suite.SuiteClasses({TestSuiteRunner1.class, 
    TestSuiteRunner2.class})
public class AllTests {}


来源:https://stackoverflow.com/questions/15418466/how-to-include-multiple-categories-in-junit4

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