Utilities for testing with JUnit 4.
<dependency>
<groupId>com.ocarlsen.test</groupId>
<artifactId>junit4-test-utils</artifactId>
<version>1.1-SNAPSHOT</version>
<scope>test</scope>
</dependency>
compile 'com.ocarlsen.test:junit4-test-utils:1.0-SNAPSHOT'
Use the com.ocarlsen.test.util.Order
annotation in JUnit 4 (>= 4.13)
like you would the org.junit.jupiter.api.Order
annotation in JUnit 5.
@OrderWith(OrderAnnotation.class)
public class ExampleTest {
private static int counter = -2;
@BeforeClass
public static void checkCounter_2() {
assertThat(counter, is(-2));
}
@AfterClass
public static void checkCounter2() {
assertThat(++counter, is(2));
}
@Order(-1)
@Test
public void test_1() {
assertThat(++counter, is(-1));
}
@Test
public void test() {
assertThat(++counter, is(0));
}
@Order(1)
@Test
public void test1() {
assertThat(++counter, is(1));
}
}
This example is demonstrated in ExampleTest.