๋ฐ์ํ
๐ JUnit5 assertThat vs assertAll vs assertSoftly
ํ์ ํ ์คํธ ์ฝ๋๋ฅผ ์์ฑํ ๋ assertThat ํน์ assertAll ๋ด๋ถ์ assertThat์ ์์ฑํ์๋๋ฐ์, ์ด๋ฒ์ SoftAssertions์ assertSoftly๋ผ๋ ๊ฒ์ฆ ๋ฉ์๋๋ฅผ ์๊ฒ๋์ด ๊ฐ๋ตํ ์ ๋ฆฌํด๋ณด๊ณ ์ ํฉ๋๋ค. ๐
โ๏ธ ํ ์คํธ ์ฝ๋
import org.junit.jupiter.api.Test;
import static org.assertj.core.api.Assertions.assertThat;
import static org.assertj.core.api.SoftAssertions.assertSoftly;
import static org.junit.jupiter.api.Assertions.assertAll;
public class ExampleTest {
private final int num1 = 5;
private final int num2 = 10;
private final int actual = num1 + num2;
@Test
void assertThatTest() {
assertThat(actual).isEqualTo(15);
assertThat(actual).isEqualTo(20);
assertThat(actual).isEqualTo(15);
assertThat(actual).isEqualTo(10);
}
@Test
void assertAllTest() {
assertAll(
() -> assertThat(actual).isEqualTo(15),
() -> assertThat(actual).isEqualTo(20),
() -> assertThat(actual).isEqualTo(15),
() -> assertThat(actual).isEqualTo(10)
);
}
@Test
void assertSoftlyTest() {
assertSoftly(softly -> {
softly.assertThat(actual).isEqualTo(15);
softly.assertThat(actual).isEqualTo(20);
softly.assertThat(actual).isEqualTo(15);
softly.assertThat(actual).isEqualTo(10);
});
}
}
โ๏ธ assertThat
- assert๋ฌธ์ด ์ฌ๋ฌ๊ฐ ์ผ ๊ฒฝ์ฐ, ๊ฒ์ฆ์ ์คํจํ๋ฉด ์ดํ assert๋ ์คํํ์ง ์์
โ๏ธ assertAll
- assert๋ฌธ์ด ์ฌ๋ฌ๊ฐ ์ด๋๋ผ๋ ๋ชจ๋ assert๋ฅผ ๊ฒ์ฆ ํ ์คํจํ ํ ์คํธ ์ฝ๋์ ์์๊ฐ, ์ค์ ๊ฐ์ ์ถ๋ ฅ
โ๏ธ assertSoftly
- assertAll()๊ณผ ๋ง์ฐฌ๊ฐ์ง๋ก ์คํจํ๋ ์ฑ๊ณตํ๋ ๋ชจ๋ assert๋ฌธ์ ์คํํ ํ ์คํจํ ํ ์คํธ ์ฝ๋์ ์์น๊ฐ, ์ค์ ๊ฐ์ ์ถ๋ ฅ
- assertAll()๊ณผ๋ ๋ฌ๋ฆฌ ์คํจํ ์ฝ๋์ ๋ผ์ธ ์์น๊น์ง ๋ณด์ฌ์ฃผ๊ธฐ์ ์ ์ฉํ ๋ฏ ํจ
๐ ๊ฒฐ๋ก (๊ฐ์ธ์ ์ธ ...)
- ๋จ์ผ Assert -> assertThat
- ์ฌ๋ฌ ๊ฐ์ assert -> assertSoftly
๋ฐ์ํ
'Spring' ์นดํ ๊ณ ๋ฆฌ์ ๋ค๋ฅธ ๊ธ
Spring AOP๋ฅผ ์ฌ์ฉํ์ฌ ํด๋ผ์ด์ธํธ์ ์์ฒญ ์ ๋ณด ๋ก๊น ํ๊ธฐ (0) | 2023.01.14 |
---|---|
Spring + MyBatis์์ ์ฟผ๋ฆฌ์ ๊ฒฐ๊ณผ์ ๊ฐ์ฒด๊ฐ ๋งคํ์ด ๋๋ ๊ณผ์ (1) | 2022.10.03 |
Spring Boot profiles ์ค์ ํ๊ธฐ (1) | 2022.09.05 |
Spring Thread, Transaction, Connection ๊ด๊ณ (0) | 2022.09.03 |
Spring Data MongoDB Array field $elemMatch(MongoRepository Custom) (2) | 2022.08.20 |
๋๊ธ