1

TestNG 6.8.8

I have the following interface:

public interface Act1{
    /**
    * Some contract
    */
    public String doAct(String input);
}

and a couple of its implementations

public class Act1Impl1 implements Act1{
   //...
}

public class Act1Impl2 implements Act1{
   //...
}

The issue is there are some general contracts which implementations must follow and I'd like to write a test for this common functionality in a separate test class, like this:

public class CommonAct1Test{

    @Test
    public void test_Case1(){ 
        Act1 act1; 
        //test act1 case 1
    }

    @Test
    public void test_Case2(){
        Act1 act1; 
        //test act1 case 2
    }

}

The problem here is that it's possible to add other implementations of Act1 in the future. So, I need a way to easily add these implementations to the test.

Why do I think @DataProvider doesn't fit? Because (as far as I understood) its main purpose is to support DDT, therefore provide different data sets for testing a single unit. But in my case I test different units on the same data set.

How could I do this correctly with TestNG. In JUnit we have @RunWith and a parameterized test as shown in this asnwer

Community
  • 1
  • 1
user3663882
  • 6,957
  • 10
  • 51
  • 92

1 Answers1

1

You can achieve this through dataprovider as such, as such your data IS different implementations of the interface. Just so happens instead of actual data, code is your data :).

You can look at testng Factory - achieves the same thing but probably you will get the feeling you are looking for - "test different units on the same data set"

niharika_neo
  • 8,441
  • 1
  • 19
  • 31