Question

Is the order of the test methods in a Test Suite by JUnit4Spring reliable?

Otherwise, is there anyway to enforce the order?

Thank you a lot.

Was it helpful?

Solution

The SpringJUnit4ClassRunner is great!
If you are using JUnit 4.11, you can also use the @FixMethodOrder annotation
See example:

import org.junit.runners.MethodSorters;

import org.junit.FixMethodOrder;
import org.junit.Test;

@FixMethodOrder(MethodSorters.NAME_ASCENDING)
public class SampleTest {

    @Test
    public void firstTest() {
        System.out.println("first");
    }

    @Test
    public void secondTest() {
        System.out.println("second");
    }
}
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top