title: TestNG: Skip iteration based on logic
body: <p>I have seen many answers on how to skip the <strong>whole @Test</strong>, but I am trying to skip a specific <em>iteration</em> without having to adding extra metadata to dozens of existing tests:</p>
  
  <pre><code>public class TestNgPlayground {
  
          public static final DayOfWeek SOME_CONST = DayOfWeek.TUESDAY;
  
          @DataProvider
          public Object[][] getStuff(){
              return new Object[][] {
                      { "param1", DayOfWeek.MONDAY},    // Skip this
                      { "param2", DayOfWeek.TUESDAY },  // Run this
                      { "param3", DayOfWeek.WEDNESDAY } // Skip this
              };
          }
  
          // Ideally I want to detect and Skip in @BeforeMethod / @BeforeClass
  
          @BeforeMethod  // testArgs fetches the DataProvider values
          public void setUp(Object[] testArgs,ITestResult result ){ 
  
              DayOfWeek dataProviderValue = (DayOfWeek) testArgs[1];
  
              if(dataProviderValue!= SOME_CONST ) {
      //            throw new SkipException("skip test"); // No good - skips the entire Test
      //            result.setStatus(ITestResult.SKIP);   // Doesn't do anything
              }
          }
  
  
          @Test(dataProvider = "getStuff")
          public void testt(String param1, DayOfWeek param2){
              // some testing
          }
  
          // 2nd best option - overwrite to Skip after test has run, 
          // though time has been wasted
          @AfterMethod
          public void tearDown(ITestResult result){
  
              DayOfWeek dow = (DayOfWeek) result.getParameters()[1];
  
              if(dow != SOME_CONST){
                  result.setStatus(ITestResult.SKIP); // Doesn't do anything either... ?
              }
  
  
          }
      }
  </code></pre>
  
  <p>For the above example, I want the final report to show:</p>
  
  <p>Iteration 1 - Skipped</p>
  
  <p>Iteration 2 - Passed</p>
  
  <p>Iteration 3 - Skipped</p>