@Test@DisplayName("상품 등록이 성공해야 한다")void 상품_등록_성공() { // Given: 테스트를 위한 준비 String name = "아메리카노"; int price = 4500; ProductService productService = new ProductService(); // When: 실제 테스트할 동작 수행 productService.register(name, price); // 검증(Assert) 로직이 아직 없습니다!}
package com.example.tdd_study.product;import org.junit.jupiter.api.Test;import org.junit.jupiter.api.DisplayName;import static org.assertj.core.api.AssertionsForClassTypes.assertThat;class ProductServiceTest { @Test @DisplayName("상품 등록이 성공해야 한다") void 상품_등록_성공() { // Given: 테스트를 위한 준비 String name = "아메리카노"; int price = 4500; ProductService productService = new ProductService(); // When: 실제 테스트할 동작 수행 productService.register(name, price); // 등록된 상품을 가져와서 검증 Product product = productService.findProduct(); assertThat(product.getName()).isEqualTo("아메리카노"); }}
package com.example.tdd_study.product;public class ProductService { private Product product; // 상품 등록 시, 단순히 멤버 변수에 저장 public void register(String name, int price) { this.product = new Product(name, price); } // 등록된 상품을 반환 public Product findProduct() { return this.product; }}