How to disable TestNG test based on a condition

前端 未结 7 1330
挽巷
挽巷 2020-12-05 07:23

Is there currently a way to disable TestNG test based on a condition

I know you can currently disable test as so in TestNG:

@Test(en         


        
7条回答
  •  [愿得一人]
    2020-12-05 07:41

    An easier option is to use the @BeforeMethod annotation on a method which checks your condition. If you want to skip the tests, then just throw a SkipException. Like this:

    @BeforeMethod
    protected void checkEnvironment() {
      if (!resourceAvailable) {
        throw new SkipException("Skipping tests because resource was not available.");
      }
    }
    

提交回复
热议问题