I have developed some classes with similar behavior, they all implement the same interface. I implemented a factory that creates the appropriate object and returns the inte
If your Factory returns a concrete instance you can use the @Parameters annotation in order to obtain a more flexible automatic unit test.
package it.sorintlab.pxrm.proposition.model.factory.task;
import org.junit.Test;
import java.util.Arrays;
import java.util.Collection;
import org.junit.runner.RunWith;
import org.junit.runners.Parameterized;
import org.junit.runners.Parameterized.Parameters;
import static org.junit.Assert.*;
@RunWith(Parameterized.class)
public class TaskFactoryTest {
@Parameters
public static Collection
This example is made using Junit4. You can notice that with only one line of code you can test all the result of your Factory method.