0

I provide data to the test using a data provider. The test class has 3 tests. I want the three tests to run in sequence for every instance of data provided by data-provider. I tried the following , but this runs testOne for completely for all the data provided by data-provider and then testTwo and then testThree.

public class TestClass{

    @Test(@dataProvider = "getData")
    public void testOne(){
         //Test case logic
      }

    @Test(@dataProvider = "getData")
    public void testTwo(){
         //Test case logic
      }

    @Test(@dataProvider = "getData")
    public void testThree(){
         //Test case logic
      }

    @DataProvider
    public Object[][] getData() {
        //data provider code
      }

}

Could anyone tell me how to run the three tests for the data instance provided by the data-provider and then run the three tests for the next data instance and so on..

Thanks

sujith
  • 665
  • 2
  • 9
  • 22
  • I would think the unit test is wrong if it must rely on the method and test data call order. Can you explain why you need such restriction? – Gedrox Sep 25 '15 at 09:06
  • HI Gedrox ..I am not trying this for a unit test . We are trying to have a functional test a UI level . Each test tests for a particular scenario on the front end. Each test involves opening a browser instance . We do not want to open the browser instance for all the tests as that would result in a delay in the test execution time. – sujith Sep 25 '15 at 09:15
  • Maybe this question helps – http://stackoverflow.com/questions/358802/junit-test-with-dynamic-number-of-tests. – Gedrox Sep 25 '15 at 09:32

1 Answers1

0

This will do the trick:

public class TestClass {

  @Test(dataProvider = "getData")
  public void allTests() {
    testOne();
    testTwo();
    testThree();
  }

  private void testOne(){
     //Test case logic
  }
  private void testTwo(){
     //Test case logic
  }
  public void testThree(){
     //Test case logic
  }

  @DataProvider
  public Object[][] getData() {
    //data provider code
  }

}
Gedrox
  • 3,592
  • 1
  • 21
  • 29