์ถ์ฒ : ๋ด์ผ๋ฐฐ์์บ ํ
๋จ์ ํ ์คํธ : ํ๋ก๊ทธ๋จ์ ์์ ๋จ์๋ก ์ชผ๊ฐ ๋ฌธ์ ๋ฐ์์ ์์ธํ์ ์ ๋ณด๋ค ํจ์จ์ ์ผ๋ก ํ๊ธฐ ์ํ ํ ์คํธ ๋ฐฉ๋ฒ
๊ฐ๋ฐ ํ๋ก์ธ์ค
1. ๊ฐ๋ฐ
2. ๋จ์ ํ ์คํธ : ๊ฐ๋ฐ์ ํ ์คํธ
3. QA Testing :
- ๋ธ๋๋ฐ์ค ํ ์คํ : ์ฌ์ฉ์ ๊ด์ ํ ์คํธ
4. Production(๋ฐฐํฌ)
TDD๋?
Test-Driven Development์ ์ฝ์๋ก ํ ์คํธ ์ฝ๋๋ฅผ ๋จผ์ ์์ฑํ๊ณ ํ ์คํธ ํ ์ค์ ์ฝ๋๋ฅผ ํ ์คํธ ์ฝ๋๋ฅผ ๋ฐ๋ผ ๊ฐ๋ฐํ๋ ๊ฒ
~ ์ค๊ณ - ํ ์คํธ - ๊ฐ๋ฐ ์์
ํ ์คํธ ์ฝ๋ ๋ฐฉ๋ฒ๋ก :
Given - When - Then ~ ์ค๋น - ์คํ - ๊ฒ์ฆ ํจํด
package com.sparta.myselectshop.entity;
import com.sparta.myselectshop.dto.ProductRequestDto;
import org.junit.jupiter.api.DisplayName;
import org.junit.jupiter.api.Test;
import static org.junit.jupiter.api.Assertions.*;
// (1)
class ProductTest {
@Test // (2)
@DisplayName("์ ์ ์ผ์ด์ค") // (3)
void createProduct_Normal() {
// (4) given - ์ค๋น!
Long userId = 100L;
String title = "์ค๋ฆฌ์จ ๊ผฌ๋ถ์นฉ ์ด์ฝ์ธ๋ฌ์ค๋ง 160g";
String image = "https://shopping-phinf.pstatic.net/main_2416122/24161228524.20200915151118.jpg";
String link = "https://search.shopping.naver.com/gate.nhn?id=24161228524";
int lprice = 2350;
ProductRequestDto requestDto = new ProductRequestDto(
title,
image,
link,
lprice
);
// (5) when - ํ
์คํธํ๋ ค๋ ๋ก์ง ์ํ!
Product product = new Product(requestDto, userId);
// (6) then - ๊ฒ์ฆ!
assertNull(product.getId()); // (6-a)
assertEquals(userId, product.getUserId()); // (6-b)
assertEquals(title, product.getTitle());
assertEquals(image, product.getImage());
assertEquals(link, product.getLink());
assertEquals(lprice, product.getLprice());
assertEquals(0, product.getMyprice());
}
}
(1) ํ ์คํธ ํด๋์ค๊ฐ ์๋ ์์ฑ
(2) ํ ์คํธ ํด๋์ค์ ๋ฉ์๋๊ฐ ํ๋์ ํ ์คํธ ์ผ์ด์ค๋ฅผ ๋ํ๋ด๊ณ , @Test๋ก ์ปดํจํฐ์๊ฒ ์๋ ค์ค๋ค.
(3) ํ ์คํธ ๋ผ๋ฒจ๋ง ์ด๋ ธํ ์ด์
(4) given
(5) when
(6) then
assertNull์ ์ฃผ์ด์ง ์ธ์๊ฐ null์ด์ด์ผ ํ ์คํธ๋ฅผ ํต๊ณผ
assertEquals ํจ์๋ ์ฃผ์ด์ง ์ธ์ ๋ ๊ฐ๊ฐ ๊ฐ์์ผ ํ ์คํธ๋ฅผ ํต๊ณผ
ํ ์คํธ ์ผ์ด์ค๋ ๋ฉ์๋๊ฐ ์๋๋ผ ๋ก์ง์ ๋จ์๋ก ๋ถ๋ฅํ๋ค.
์ฃ์ง ์ผ์ด์ค๋ฅผ ๊ณ ๋ คํ ๋จ์ ํ ์คํธ :
// ํ์ Id
Long userId = 1230L;
// ์ํ๋ช
String title = "์ค๋ฆฌ์จ ๊ผฌ๋ถ์นฉ ์ด์ฝ์ธ๋ฌ์ค๋ง 160g";
// ์ํ ์ด๋ฏธ์ง URL
String image = "https://shopping-phinf.pstatic.net/main_2416122/24161228524.20200915151118.jpg";
// ์ํ ์ต์ ๊ฐ ํ์ด์ง URL
String link = "https://search.shopping.naver.com/gate.nhn?id=24161228524";
// ์ํ ์ต์ ๊ฐ
int lprice = 2350;
1. ํ์ Id
1) ํ์ Id๊ฐ null๋ก ๋ค์ด์จ๋ค๋ฉด, ๊ด์ฌ์ํ์ ๋ฑ๋กํ ๊ฒฝ์ฐ ๋๊ตฌ์ ์ํ์ผ๋ก ๋ฑ๋ก๋๋์ง
2) ํ์ Id๊ฐ ๋ง์ด๋์ค ๊ฐ์ด๋ผ๋ฉด,
2. ์ํ๋ช
1) ์ํ๋ช ๊ฐ์ด null์ด๋ผ๋ฉด,
2) ์ํ๋ช ์ด ๋น ๋ฌธ์์ด์ธ ๊ฒฝ์ฐ, ์ ์ฅ์ ํด์ผ๋ ์ง? ๊ทธ๋ฆฌ๊ณ ์ ์ฅํ๋ค๋ฉด, UI ํ์ ๋ฐฉ์์?
3. ์ํ ์ด๋ฏธ์ง URL
1) ์ํ ์ด๋ฏธ์ง URL์ด null๋ก ๋ค์ด์ค๋ ๊ฒฝ์ฐ,
2) ์ํ ์ด๋ฏธ์ง URL์ด URL ํํ๊ฐ ์๋๋ผ๋ฉด,
4. ์ํ ์ต์ ๊ฐ URL
1) ์ํ ์ต์ ๊ฐ URL์ด null์ธ ๊ฒฝ์ฐ,
2) ์ํ ์ต์ ๊ฐ URL์ด URL ํํ๊ฐ ์๋ ๊ฒฝ์ฐ,
5. ์ํ ์ต์ ๊ฐ
1) ์ํ ์ต์ ๊ฐ๊ฐ 0์ด๋ผ๋ฉด,
2) ์ํ ์ต์ ๊ฐ๊ฐ ์์๋ผ๋ฉด,
@BeforeEach : Given์ ์ญํ , ๊ธฐ๋ณธ๊ฐ์ ํ ๋นํด๋๋ค
๋จ์ํ ์คํธ์ Mock Object
์ด์์ ์ผ๋ก, ๊ฐ ํ ์คํธ ์ผ์ด์คํ ์๋ก ๋ถ๋ฆฌ๋์ด์ผ ํ๋ค. ๊ฐ์ง ๊ฐ์ฒด(Mock Object)๋ฅผ ์์ฑํ๋ ๊ฒ๋ ์ข์ ๋ฐฉ๋ฒ์ด๋ค.
Mockito : Mock ๊ฐ์ฒด๋ฅผ ๊ด๋ฆฌํ๋ ๋ผ์ด๋ธ๋ฌ๋ฆฌ
https://javadoc.io/doc/org.mockito/mockito-core/latest/org/mockito/Mockito.html
Mockito - mockito-core 4.10.0 javadoc
Latest version of org.mockito:mockito-core https://javadoc.io/doc/org.mockito/mockito-core Current version 4.10.0 https://javadoc.io/doc/org.mockito/mockito-core/4.10.0 package-list path (used for javadoc generation -link option) https://javadoc.io/doc/org
javadoc.io
'Spring๐' ์นดํ ๊ณ ๋ฆฌ์ ๋ค๋ฅธ ๊ธ
Spring Exception (0) | 2022.12.29 |
---|---|
Spring AOP (0) | 2022.12.28 |
OAuth2 (0) | 2022.12.27 |
์คํ๋ง ์๋ จ : Project MySelectShop (3) (0) | 2022.12.15 |
์คํ๋ง ์๋ จ : Project MySelectShop (2) (0) | 2022.12.15 |