Try JUnitParams . Your test will look like this:
@RunWith(JUnitParamsRunner.class) public class ExampleTest { // this method provides parameters for simpleMovingAverage public static Iterable<Integer> parametersForSimpleMovingAverage() { return IntStream.rangeClosed(1, 61).boxed().collect(Collectors.toList()); } @Parameters @Test public void simpleMovingAverage(int days) { double sma = -1; int size = stock.getCloses().size(); stock.calcSMA(days); // <- code that I'm testing // first days should be -1 for (int index = size - 1; index >= size - days + 1; --index) { assertEquals(-1, stock.getSMA(days, index), 0.001); } for (int index = size - days - 1; index >= 0; --index) { sma = 0.0; for (int i = 0; i < days; ++i) { sma += stock.getCloses().get(index + i); } sma /= days; assertEquals(sma, stock.getSMA(days, index), 0.001); } }
And when you run the test, you will get a report as you like. Even better, unlike the standard JUnit Parametrized runner. The JUnitPramsRunner report will contain not only the index of the test case, but also a parameter for each case (sorry, I do not have enough reputation to post a screenshot).
Note: you will need to add a dependency:
source share