Grouping JUnit tests

前端 未结 7 1853
[愿得一人]
[愿得一人] 2020-11-27 04:27

Is there any way to group tests in JUnit, so that I can run only some groups?

Or is it possible to annotate some tests and then globally disable them?

I\'m u

相关标签:
7条回答
  • 2020-11-27 04:51

    JUnit 4.8 supports grouping:

    public interface SlowTests {}
    public interface IntegrationTests extends SlowTests {}
    public interface PerformanceTests extends SlowTests {}
    

    And then...

    public class AccountTest {
    
        @Test
        @Category(IntegrationTests.class)
        public void thisTestWillTakeSomeTime() {
            ...
        }
    
        @Test
        @Category(IntegrationTests.class)
        public void thisTestWillTakeEvenLonger() {
            ...
        }
    
        @Test
        public void thisOneIsRealFast() {
            ...
        }
    }
    

    And lastly,

    @RunWith(Categories.class)
    @ExcludeCategory(SlowTests.class)
    @SuiteClasses( { AccountTest.class, ClientTest.class })
    public class UnitTestSuite {}
    

    Taken from here: https://community.oracle.com/blogs/johnsmart/2010/04/25/grouping-tests-using-junit-categories-0

    Also, Arquillian itself supports grouping: https://github.com/weld/core/blob/master/tests-arquillian/src/test/java/org/jboss/weld/tests/Categories.java

    0 讨论(0)
提交回复
热议问题