I want to do a batch test like the following, however if there is an error, it does not tell me which value of i
the error occurs in.
@Test
public void simpleMovingAverageBatch() {
for (int i = 1; i < 61; ++i) {
simpleMovingAverage(i);
}
}
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);
}
}
This is an example of what happens if I run the code as is:
This is an example of what I want to have happen:
I've taken a look at Parameterized Tests in this tutorial, however I do not know if this the route I want to take.
Any tips?
I don't think this question is a duplicate of these:
Running the same JUnit test case multiple time with different data