Home | History | Annotate | Download | only in dataprovider
      1 package test.dataprovider;
      2 
      3 import org.testng.Assert;
      4 import org.testng.ITestContext;
      5 import org.testng.annotations.DataProvider;
      6 import org.testng.annotations.Test;
      7 
      8 /**
      9  * Used by {@link TestNG411Test}. Do not change number of methods or method names
     10  * @author nullin
     11  *
     12  */
     13 public class TestNG411SampleTest
     14 {
     15   private static final String CHECK_MAX_DATA = "checkMaxData";
     16   private static final String CHECK_MIN_DATA = "checkMinData";
     17 
     18   @DataProvider(name = CHECK_MAX_DATA)
     19   public Object[][] dataProviderCheckMax() {
     20     return new Object[][] {
     21       { 1, 2, 3, 3 },
     22     };
     23   }
     24 
     25   @Test(description = "Number of parameters to this test don't match the " +
     26       "ones passed by data provider", dataProvider = CHECK_MAX_DATA)
     27   public void checkMaxTest(int nr1, int nr2, int expected) {
     28     Assert.fail("This code shouldnt be executed");
     29   }
     30 
     31   @DataProvider(name = CHECK_MIN_DATA)
     32   public Object[][] dataProviderCheckMin() {
     33     return new Object[][] {
     34       { 1, 2, },
     35     };
     36   }
     37 
     38   @Test(description = "Number of parameters to this test don't match the " +
     39       "ones passed by data provider", dataProvider = CHECK_MIN_DATA)
     40   public void checkMinTest(int nr1, int nr2, int expected) {
     41     Assert.fail("This code shouldnt be executed");
     42   }
     43 
     44   @Test(description = "Number of parameters to this test don't match the " +
     45         "ones passed by data provider. But an ojbect will be injected",
     46         dataProvider = CHECK_MIN_DATA)
     47   public void checkMinTest_injection(int nr1, int nr2, ITestContext ctx) {
     48     int result = Math.min(nr1, nr2);
     49     Assert.assertEquals(result, nr1);
     50     Assert.assertNotNull(ctx);
     51   }
     52 }
     53