0

TestNG 6.8.8

I have the following interface and implementation:

public interface HolderService {
    String str();
    //other-methods
}

public interface Act1{
    public String action(Collection<HolderService> context);
}

//The action class for testing    
public class ActImpl implements Act1{
    public String action(Collection<HolderService> context){
        //implementation
    }
}

The problem is the implementation of the HolderService is kind of messy to initialize it with test data which makes the test be quite large.

So my first thought was to write a simple test implementation and supply it with test data like this:

public class ActImplTest{

    @Test
    public void some_Test(){
        //...
    }

    private static class ServiceHolderTestImpl implemets HolderService{
        //Just a JavaBean with getters and setters
    }
}

But it looks a little wierd that in order for to make tests look simpler I need to provide some test implementation. Maybe there is another way to deal with the problem. I also looked at Parametrization, shown in this example, but it doesn't seem fit my needs.

Community
  • 1
  • 1
user3663882
  • 6,957
  • 10
  • 51
  • 92
  • 1
    That sounds like you want to use a mock of HolderService, right? In that case have a look at mocking frameworks like Mockito etc. – Thomas Jul 19 '16 at 13:20
  • @Thomas Well, yes. But not in the way like [this](http://websystique.com/java/testing/testng-mockito-example-stubbing-void-methods/). I need a collection of initialized mock-instances, so mock-injection doesn't fit here. – user3663882 Jul 19 '16 at 13:21

0 Answers0