When I'm running my SpringBootTests (using gradle) I have noticed that Test 3 always runs first. I would like understand how gradle decides the order of tests and I would like to be able to control the order and have Test 1 run first. I know that JUnit5 allows this, however I'm interested to hear whether a similar feature exists for SpringBootTests.
Thank you!
@SpringBootTest(webEnvironment = SpringBootTest.WebEnvironment.RANDOM_PORT)
class ControllerTest {
@LocalServerPort
private int port;
@Autowired
TestRestTemplate restTemplate;
@Test
void returnSomething1() {
assertThat(this.restTemplate.getForObject("http://localhost:" + port + "/hello",
String.class)).contains("hello");
@Test
void returnSomething2() {
assertThat(this.restTemplate.getForObject("http://localhost:" + port + "/yo",
String.class)).contains("yo");
@Test
void returnSomething3() {
assertThat(this.restTemplate.getForObject("http://localhost:" + port + "/bye",
String.class)).contains("bye");
@SpringBootTestannotation together with the@TestMethodOrderannotation.