Слайд 13
Параметризованный тест
package org.cud.calc;
import static org.junit.Assert.assertEquals;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.junit.runners.Parameterized.Parameters;
import java.util.Arrays;
import java.util.Collection;
@RunWith(value =
org.junit.runners.Parameterized.class)
public class CalculatorParamTest {
int result;
int[] numbers;
@Parameters
public static Collection parameters() {
return Arrays.asList(new int[][][] { { { 2 }, { 1, 1 } },
{ { -2 }, { -1, -1 } }, { { 9 }, { 2, 3, 4 } }, { { 0 }, {} },
{ { 0 }, { 0, 0, 0, 0 } } });
}
public CalculatorParamTest(int[] result, int[] numbers) {
this.result = result[0];
this.numbers = numbers;
}
@Test
public void testSum() {
Calculator calculator = new Calculator();
assertEquals(result, calculator.sum(numbers));
}
}