File tree Expand file tree Collapse file tree
src/test/java/net/developerden/backend/controller Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -30,4 +30,7 @@ tasks {
3030 withType<JavaCompile > {
3131 options.encoding = " UTF-8"
3232 }
33+ withType<Test > {
34+ useJUnitPlatform()
35+ }
3336}
Original file line number Diff line number Diff line change 1+ package net .developerden .backend .controller ;
2+
3+ import org .junit .jupiter .api .Test ;
4+
5+ import org .springframework .beans .factory .annotation .Autowired ;
6+ import org .springframework .boot .test .context .SpringBootTest ;
7+ import org .springframework .boot .test .context .SpringBootTest .WebEnvironment ;
8+ import org .springframework .boot .test .web .client .TestRestTemplate ;
9+ import org .springframework .boot .web .server .LocalServerPort ;
10+
11+ import static org .assertj .core .api .Assertions .assertThat ;
12+
13+ @ SpringBootTest (webEnvironment = WebEnvironment .RANDOM_PORT )
14+ public class InfoControllerTest {
15+
16+ @ LocalServerPort
17+ private int port ;
18+
19+ @ Autowired
20+ private TestRestTemplate restTemplate ;
21+
22+ private String baseUrl = "http://localhost:" + port ;
23+
24+ @ Test
25+ public void ping_happyDay_returnsPong () {
26+ String response = this .restTemplate .getForObject (baseUrl + "/ping" , String .class );
27+ assertThat (response ).isEqualTo ("pong" );
28+ }
29+ }
You can’t perform that action at this time.
0 commit comments