Skip to content

Commit 81bdad5

Browse files
committed
fix test order
1 parent 250be38 commit 81bdad5

4 files changed

Lines changed: 25 additions & 15 deletions

File tree

build.gradle

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
plugins {
22
id 'java'
33
id 'war'
4+
id 'com.adarshr.test-logger' version '4.0.0'
45
id 'org.springframework.boot' version '3.5.5'
56
id 'io.spring.dependency-management' version '1.1.7'
67
}

src/test/java/de/kaleidox/workbench/test/api/CustomerApiTest.java

Lines changed: 18 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,10 @@
22

33
import de.kaleidox.workbench.model.jpa.representant.Customer;
44
import de.kaleidox.workbench.repo.CustomerRepository;
5+
import org.junit.jupiter.api.MethodOrderer;
56
import org.junit.jupiter.api.Order;
67
import org.junit.jupiter.api.Test;
8+
import org.junit.jupiter.api.TestMethodOrder;
79
import org.springframework.beans.factory.annotation.Autowired;
810
import org.springframework.boot.test.context.SpringBootTest;
911
import org.springframework.boot.test.web.client.TestRestTemplate;
@@ -13,6 +15,7 @@
1315

1416
import static org.junit.jupiter.api.Assertions.*;
1517

18+
@TestMethodOrder(MethodOrderer.OrderAnnotation.class)
1619
@SpringBootTest(webEnvironment = SpringBootTest.WebEnvironment.DEFINED_PORT)
1720
public class CustomerApiTest {
1821
public static final String FAARQUARDT_NAME = "Lord Faarquardt";
@@ -29,7 +32,20 @@ void contextLoads() {
2932
}
3033

3134
@Test
32-
@Order(1)
35+
@Order(10)
36+
void createCustomers() {
37+
for (var customer : List.of(FAARQUARDT_CASTLE, FAARQUARDT_HOUSE)) {
38+
var response = rest.postForEntity("http://localhost:8080/api/customers", customer, Void.class);
39+
assertEquals(201, response.getStatusCode().value(), "status code mismatch");
40+
41+
var result = customers.findById(customer.key());
42+
assertTrue(result.isPresent(), "customer not found");
43+
assertEquals(customer, result.get());
44+
}
45+
}
46+
47+
@Test
48+
@Order(11)
3349
void fetchNames() {
3450
var response = rest.getForEntity("http://localhost:8080/api/customers/names", String[].class);
3551
assertTrue(response.getStatusCode().is2xxSuccessful(), "request unsuccessful");
@@ -41,7 +57,7 @@ void fetchNames() {
4157
}
4258

4359
@Test
44-
@Order(2)
60+
@Order(12)
4561
void fetchDepartments() {
4662
var response = rest.getForEntity("http://localhost:8080/api/customers/%s/departments".formatted(FAARQUARDT_NAME),
4763
String[].class);
@@ -53,17 +69,4 @@ void fetchDepartments() {
5369
assertNotEquals(-1, Arrays.binarySearch(data, "Castle"), "department not found");
5470
assertNotEquals(-1, Arrays.binarySearch(data, "House"), "department not found");
5571
}
56-
57-
@Test
58-
@Order(10)
59-
void createCustomers() {
60-
for (var customer : List.of(FAARQUARDT_CASTLE, FAARQUARDT_HOUSE)) {
61-
var response = rest.postForEntity("http://localhost:8080/api/customers", customer, Void.class);
62-
assertEquals(201, response.getStatusCode().value(), "status code mismatch");
63-
64-
var result = customers.findById(customer.key());
65-
assertTrue(result.isPresent(), "customer not found");
66-
assertEquals(customer, result.get());
67-
}
68-
}
6972
}

src/test/java/de/kaleidox/workbench/test/api/TimetableApiTest.java

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,17 @@
11
package de.kaleidox.workbench.test.api;
22

33
import de.kaleidox.workbench.repo.TimetableEntryRepository;
4+
import org.junit.jupiter.api.MethodOrderer;
45
import org.junit.jupiter.api.Order;
56
import org.junit.jupiter.api.Test;
7+
import org.junit.jupiter.api.TestMethodOrder;
68
import org.springframework.beans.factory.annotation.Autowired;
79
import org.springframework.boot.test.context.SpringBootTest;
810
import org.springframework.boot.test.web.client.TestRestTemplate;
911

1012
import static org.junit.jupiter.api.Assertions.*;
1113

14+
@TestMethodOrder(MethodOrderer.OrderAnnotation.class)
1215
@SpringBootTest(webEnvironment = SpringBootTest.WebEnvironment.DEFINED_PORT)
1316
public class TimetableApiTest {
1417
@Autowired private TimetableEntryRepository entries;

src/test/java/de/kaleidox/workbench/test/api/UserApiTest.java

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,10 @@
22

33
import de.kaleidox.workbench.model.jpa.representant.User;
44
import de.kaleidox.workbench.repo.UserRepository;
5+
import org.junit.jupiter.api.MethodOrderer;
56
import org.junit.jupiter.api.Order;
67
import org.junit.jupiter.api.Test;
8+
import org.junit.jupiter.api.TestMethodOrder;
79
import org.springframework.beans.factory.annotation.Autowired;
810
import org.springframework.boot.test.context.SpringBootTest;
911
import org.springframework.boot.test.web.client.TestRestTemplate;
@@ -12,6 +14,7 @@
1214

1315
import static org.junit.jupiter.api.Assertions.*;
1416

17+
@TestMethodOrder(MethodOrderer.OrderAnnotation.class)
1518
@SpringBootTest(webEnvironment = SpringBootTest.WebEnvironment.DEFINED_PORT)
1619
public class UserApiTest {
1720
public static final User USER_1 = new User("user1", "User One");

0 commit comments

Comments
 (0)