Exclude some JUnit tests from automated test suite

后端 未结 4 1186
爱一瞬间的悲伤
爱一瞬间的悲伤 2020-12-19 06:54

When writing code that interacts with external resources (such as using a web service or other network operation), I often structure the classes so that it can also be \"stu

4条回答
  •  轮回少年
    2020-12-19 07:57

    I recommend using junit categories. See this blog for details : https://community.oracle.com/blogs/johnsmart/2010/04/25/grouping-tests-using-junit-categories-0.

    Basically, you can annotate some tests as being in a special category and then you can set up a two test suites : one that runs the tests of that category and one that ignores tests in that category (but runs everything else)

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

    }

    you can even annotate individual tests"

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

    Anytime I see something manually getting turned on or off I cringe.

提交回复
热议问题