Exclude individual test from 'before' method in JUnit

前端 未结 6 1994
耶瑟儿~
耶瑟儿~ 2021-01-04 00:16

All tests in my test class execute a \'before\' method (annotated with JUnit\'s @Before) before the execution of each test.

I need a particular test not

6条回答
  •  生来不讨喜
    2021-01-04 01:15

    Consider using the @Enclosed runner to allow you to have two inner test classes. One with the required @Before method, the other without.

    Enclosed

    @RunWith(Enclosed.class)
    public class Outer{
    
        public static class Inner1{
    
         @Before public void setup(){}
    
         @Test public void test1(){}
        }
    
      public static class Inner2{
    
       // include or not the setup
       @Before public void setup2(){}
    
       @Test public void test2(){}
      }
    
    }
    

提交回复
热议问题