Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

In Eclipse, how do I run a JUnit test case multiple times

I have a unit test that fails sometimes and debugging it is a pain because I don't know why it sometimes fails.

Is there a way inside Eclipse that I can run a JUnit test 5 times or 50 times or something?

Thanks.

like image 786
Thom Avatar asked Jan 10 '12 14:01

Thom


2 Answers

I just found the following solution which doesn't require any additional depedency (Spring is required for one of the answers you got).

Run your test with the Parameterized runner:

@RunWith(Parameterized.class)

Then add the following method to provide a number of empty parameters equals to the number of times you want to run the test:

@Parameterized.Parameters
public static List<Object[]> data() {
    return Arrays.asList(new Object[10][0]);
}

This way you don't even have to write a loop. IntelliJ and eclipse also group the results of every iteration together.

like image 144
javanna Avatar answered Nov 27 '22 16:11

javanna


Have you tried something like this?

@Test
public void runMultipleTests() {
    for (int i = 0; i < 10; i++) {
        myTestMethod();
    }
}
like image 44
Chris Avatar answered Nov 27 '22 17:11

Chris