-3

I am working on data driven testing, currently i am stuck on @Test. I want to pass the data to two different data providers and want to run one of the @test only once. How can i achieve this. Below is the same code describing my situation

 @DataProvider(name = "dp")
   public Object[][] createData(Method m) {
  System.out.println(m.getName());  // print test method name
  return new Object[][] { new Object[] { "Cedric" }};
}

@Test(dataProvider = "dp")
public void test1(String s) {
}

@Test(dataProvider = "dp")
public void test2(String s) {
}

here i want to run first @Test to run only once.Isthere any way through which this is possible?

ddb
  • 1
  • 1
  • 4
  • it should run only once anyway, because you are only providing one variable "Cedric" - what does it do if not only run once? – drkthng Oct 14 '15 at 07:42
  • Above mentioned code is only for demo, my actual also looks similar in first test i want to login to the site and in the second test i'l have all the other test operations.If suppose i have two tests as above where i want to login just once and do the operations which are there in the 2nd test. – ddb Oct 14 '15 at 08:25
  • 2
    why are you not posting the exact example you have your question for??? – drkthng Oct 14 '15 at 08:44

1 Answers1

0

Based on your comments it sounds like you want a "dependsOnMethods" in your test.

For example, if you want test1 to run before test2 every time then you need to setup test2 as such:

@Test(dependsOnMethods = "test1", alwaysRun = true, dataProvider = "dp")
public void test2(String s) {
}