[ATDD] ์ธ์ํ ์คํธ, ํ ์คํธ๊ฒฉ๋ฆฌ, ํ ์คํธ ํฝ์ค์ฒ, RestAssured
@SpringBootTest(webEnvironment = SpringBootTest.WebEnvironment.RANDOM_PORT)
- ์ค์ ์๋ฒ๋ฅผ ๋์์ API๋ฅผ ํธ์ถํ๋ End-to-End ํ
์คํธ
- ์ฌ์ฉ์ ๊ด์ ์์ ๊ธฐ๋ฅ์ด ๋์ํ๋์ง ๊ฒ์ฆ
- RANDOM_PORT: ํ
์คํธ๋ง๋ค ๋๋ค ํฌํธ๋ก ์๋ฒ ์คํ (์ถฉ๋ ๋ฐฉ์ง)
@BeforeEach
void setUp() {
databaseCleanup.execute(); // ๋งค ํ
์คํธ๋ง๋ค DB ์ด๊ธฐํ
}
- ๊ฐ ํ
์คํธ๊ฐ ๋
๋ฆฝ์ ์ผ๋ก ์คํ๋๋๋ก ๋ณด์ฅ
- ํ
์คํธ ์์์ ์์กดํ์ง ์์
public class TestFixture {
public static ExtractableResponse<Response> ์์ฝ_์์ฑ_์์ฒญ(...) { }
public static ExtractableResponse<Response> ์์ฝ_์ทจ์_์์ฒญ(...) { }
}
- ํ
์คํธ์์ ๋ฐ๋ณต ์ฌ์ฉ๋๋ ํฌํผ ๋ฉ์๋ ๋ชจ์
- ์ค๋ณต ์ฝ๋ ์ ๊ฑฐ, ๊ฐ๋
์ฑ ํฅ์
@Nested
@DisplayName("์ ์ ์ผ์ด์ค")
class HappyPath { ... }
@Nested
@DisplayName("์์ธ ์ผ์ด์ค")
class ExceptionCase { ... }
- ํ
์คํธ๋ฅผ ๋
ผ๋ฆฌ์ ์ผ๋ก ๊ทธ๋ฃนํ
- Happy Path / Exception Case ๋ถ๋ฆฌ
RestAssured
.given().log().all()
.contentType(MediaType.APPLICATION_JSON_VALUE)
.body(params)
.when().post("/api/reservations")
.then().log().all()
.extract();
- HTTP API ํ
์คํธ๋ฅผ ์ํ DSL ๋ผ์ด๋ธ๋ฌ๋ฆฌ
- given() → ์์ฒญ ์ค์ , when() → ์คํ, then() → ๊ฒ์ฆ
- ํ
์คํธ ์ ์ฉ ํ๋กํ์ผ ํ์ฑํ
- application-test.yml ์ค์ ์ฌ์ฉ (์๋ค๋ฉด)
- ํ
์คํธ ์ปจํ
์คํธ์ ํน์ ๋น์ ์๋ ๋ฑ๋ก
- ํจํค์ง ์ค์บ ๋ฒ์ ๋ฐ์ ์ปดํฌ๋ํธ ํฌํจ
| [ATDD] ํ ์คํธ ๊ฒฉ๋ฆฌ, ๋ฒ๊ทธ ์์ ์ต์ํ, ํ ์คํธ์ฝ๋์ ์ค๋ณต ์ ๊ฑฐ (0) | 2026.01.25 |
|---|