How to exclude all JUnit4 tests with a given category using Maven surefire?

后端 未结 1 1711
遥遥无期
遥遥无期 2020-12-08 11:04

I intend on annotating some of my JUnit4 tests with an @Category annotation. I would then like to exclude that category of tests from running on my Maven builds.

I s

1条回答
  •  生来不讨喜
    2020-12-08 11:38

    You can do this as follows:

    Your pom.xml should contain the following setup.

    
       
           **/TestCircle.java
            **/TestSquare.java
       
    
    

    If you want regex support just use

    
        %regex[.*[Cat|Dog].*Test.*]
    
    

    http://maven.apache.org/surefire/maven-surefire-plugin/examples/inclusion-exclusion.html

    If you want to use Category annotation, you need to do the following:

    @Category(com.myproject.annotations.Exclude)
    @Test
    public testFoo() {
       ....
    }
    

    In your maven configuration, you can have something like this

    
      com.myproject.annotations.Exclude
    
    

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