Skip to content

Commit 0f4b290

Browse files
committed
test: add InfoControllerTest
1 parent a7bd69c commit 0f4b290

2 files changed

Lines changed: 32 additions & 0 deletions

File tree

build.gradle.kts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,4 +30,7 @@ tasks {
3030
withType<JavaCompile> {
3131
options.encoding = "UTF-8"
3232
}
33+
withType<Test> {
34+
useJUnitPlatform()
35+
}
3336
}
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
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+
}

0 commit comments

Comments
 (0)