junit4 icon indicating copy to clipboard operation
junit4 copied to clipboard

Feature: @FromDataPoints applicable to fields

Open mbjelac opened this issue 9 years ago • 0 comments

Example:

@DataPoints
public static int[] numbers = new int[]{1, 2, 3, 4};

@DataPoints
public static String[] strings = new String[]{"a", "b", "c"};

@FromDataPoints
public int number; // this will be injected with 1, 2, 3 and 4 for each theory run

@Before
public void setUp() {
    Assume.assumeTrue(number % 2 == 0); // not supported
    initializeSystemWithAmount(number);
}

@Theory
public void theory(String string) {
    assertOnString(string);
}

Allows SUT initialization with datapoint values. Also allows global skipping of theories for a certain combination of datapoints.

The example shows a mix of datapoints used as fields and used as theory parameters.

Alternative 1: Allow datapoint injection in @Before and @After methods.

Alternative 2: Create @BeforeTheory and @AfterTheory method annotations which work like @Before and @After but their methods allow datapoint injection.

mbjelac avatar Oct 29 '15 11:10 mbjelac