- ์ด์ ๊ธ ํ์ธํ๊ธฐ -
[๐ป FrameWork(ํ๋ ์์ํฌ)/SpringTEST(์คํ๋งํ ์คํธ)] - 2-2 [Junit] Assertions ๋ฉ์๋
1. ํ ์คํธ ๋ฐ๋ณต
- MyCalculatorRepeatableTest๋ฅผ ์์ฑํ์ฌ ํ์ธํด๋ณด๊ฒ ์ต๋๋ค.
- ์์น : com.pcy.dayonetest (test)
@RepeatedTest(5)
public void repeatedAddTest() {
// Given - ์ค๋น
MyCalculator myCalculator = new MyCalculator(10.0);
// When - ํ๋
myCalculator.minus(5.0);
// Then - ๊ฒ์ฆ
Assertions.assertEquals(5.0, myCalculator.getResult());
}
- ํด๋น ๋ฉ์๋ ์ํ ์ ์๋์ ๊ฐ์ ์คํ๊ฒฐ๊ณผ๋ฅผ ํ์ธํ ์ ์์ต๋๋ค.
2. ์ ๋ ฅ๊ฐ ๋ค์ํ๊ฒ ์ค์
- MyCalculatorRepeatableTest์ ์์ฑํ์ฌ ํ์ธํด๋ณด๊ฒ ์ต๋๋ค.
- ์์น : com.pcy.dayonetest (test)
@DisplayName("ํ๋ผ๋ฏธํฐ๋ฅผ ๋ฃ์ผ๋ฉฐ ์ฌ์น์ฐ์ฐ 2๋ฒ ๋ฐ๋ณต ํ
์คํธ")
@ParameterizedTest
@MethodSource("parameterizedComplicatedCalculateTestParameters")
public void parameterizedComplicatedCalculateTest(
Double addValue,
Double minusValue,
Double multiplyValue,
Double divideValue,
Double expectedValue
) {
// given
MyCalculator myCalculator = new MyCalculator();
// when
Double result = myCalculator
.add(addValue)
.minus(minusValue)
.multiply(multiplyValue)
.divide(divideValue)
.getResult();
// then
Assertions.assertEquals(expectedValue, result);
}
public static Stream<Arguments> parameterizedComplicatedCalculateTestParameters() {
return Stream.of(
Arguments.of(10.0, 4.0, 2.0, 3.0, 4.0),
Arguments.of(4.0, 2.0, 4.0, 4.0, 2.0)
);
}
- @ParameterizedTest, @MethodSource ์ด๋ ธํ ์ด์ ์ ์ถ๊ฐํด์ค๋๋ค.
- MethodSource์ธ parameterizedComplicatedCalculateTestParameters ๋ฉ์๋๋ฅผ ๊ตฌํํ์ฌ ์ ๋ ฅ๊ฐ์ ๋ฉ์๋๋ก ๊ตฌํํฉ๋๋ค.
- ํด๋น ๋ฉ์๋ ์ํ ์ ์๋์ ๊ฐ์ ์คํ๊ฒฐ๊ณผ๋ฅผ ํ์ธํ ์ ์์ต๋๋ค.
3. Github์ผ๋ก ํ์ธ
์ ์ฒด ํ์ผ ํ์ธ(ํ์ฌ ๋ณ๊ฒฝ๋ด์ญ)
[Github]
์ฐธ์กฐ : ์ธํ๋ฐ ๊ฐ์ [์ฅฌ์ฅฌ์ ํจ๊ป ํ๋ฃจ๋ง์ ๋๋ด๋ ์คํ๋ง ํ ์คํธ]
'๐ป FrameWork(ํ๋ ์์ํฌ) > SpringTEST(์คํ๋งํ ์คํธ)' ์นดํ ๊ณ ๋ฆฌ์ ๋ค๋ฅธ ๊ธ
3-2 [Mocktio] ๊ฐ๋จํ ์ฑ์ ์ ์ฅ ์ ํ๋ฆฌ์ผ์ด์ ๊ตฌํ (0) | 2024.06.04 |
---|---|
3-1 [Mocktio] ๊ฐ๋จํ ์ฑ์ ์ ์ฅ ์ ํ๋ฆฌ์ผ์ด์ ๊ตฌํ(๋ก์ปฌ ํ๊ฒฝ ๊ตฌ์ฑ) (0) | 2024.06.03 |
2-3 [Junit] ํ ์คํธ์ ์ด๋ฆ๋ถ์ด๊ธฐ (0) | 2024.06.03 |
2-2 [Junit] Assertions ๋ฉ์๋ (0) | 2024.06.02 |
2-1 [Junit] ๊ฐ๋จํ ๊ณ์ฐ๊ธฐ ๊ตฌํ ๋ฐ ํ ์คํธ์ฝ๋ ์์ฑ (0) | 2024.06.02 |