1. Assertions ๋ฉ์๋
- JunitPracticeTest ์์ฑํ์ฌ ํด๋น ๋ฉ์๋ ํ์ตํ๋๋ก ํ๊ฒ ์ต๋๋ค.
- ์์น : com.pcy.dayonetest (test)
1) assertEqualsTest
@Test
public void assertEqualsTest() {
String expect = "Something";
String actual = "Something";
Assertions.assertEquals(expect, actual);
}
- ๋ ๊ฐ์ด ๋์ผํ์ง ํ์ธํฉ๋๋ค.
2) assertEqualsTest
@Test
public void assertNotEqualsTest() {
String expect = "Something";
String actual = "hello";
Assertions.assertNotEquals(expect, actual);
}
- ๋ ๊ฐ์ด ๋ค๋ฅธ์ง ํ์ธํฉ๋๋ค.
3) assertTrueTest
@Test
public void assertTrueTest() {
Integer a = 10;
Integer b = 10;
Assertions.assertTrue(a.equals(b));
}
- ์กฐ๊ฑด์ด ์ฐธ์ธ์ง ํ์ธํฉ๋๋ค.
4) assertFalseTest
@Test
public void assertFalseTest() {
Integer a = 10;
Integer b = 20;
Assertions.assertFalse(a.equals(b));
}
- ์กฐ๊ฑด์ด ๊ฑฐ์ง์ธ์ง ํ์ธํฉ๋๋ค.
5) asserThrowTest
@Test
public void asserThrowTest() {
Assertions.assertThrows(RuntimeException.class, () -> {
throw new RuntimeException("์์๋ฐ์ Error");
});
}
- ์์ธ๊ฐ ๋ฐ์ํ๋์ง ํ์ธํฉ๋๋ค.
6) assertNotNullTest
@Test
public void assertNotNullTest() {
String value = "hello";
Assertions.assertNotNull(value);
}
- ๊ฐ์ด null์ด ์๋์ง ํ์ธํฉ๋๋ค.
7) assertNullTest
@Test
public void assertNullTest() {
String value = null;
Assertions.assertNull(value);
}
- ๊ฐ์ด null์ธ์ง ํ์ธํฉ๋๋ค.
8) assertIterableTest
@Test
public void assertIterableTest() {
List<Integer> list1 = List.of(1, 2);
List<Integer> list2 = List.of(1, 2);
Assertions.assertIterableEquals(list1, list2);
}
- ๋ Iterable ๊ฐ์ฒด๊ฐ ๋์ผํ ์์๋ฅผ ํฌํจํ๊ณ ์๊ณ ์์๋ ๊ฐ์์ง ํ์ธํฉ๋๋ค.
9) assertAll
@Test
public void assertAllTest() {
String expect = "Something";
String actual = "Something";
List<Integer> list1 = List.of(1, 2);
List<Integer> list2 = List.of(1, 2);
Assertions.assertAll("Assert All", List.of(
() -> {Assertions.assertEquals(expect, actual);},
() -> {Assertions.assertIterableEquals(list1, list2);}
));
}
- ์ฌ๋ฌ ์ด์ค์ (Assertions) ๊ทธ๋ฃนํํ์ฌ ๋ชจ๋ ์คํํ๊ณ , ์คํจํ ๊ฒฝ์ฐ์๋ ๋๋จธ์ง ์ด์ค์ ๋ค์ ๊ณ์ ์คํํฉ๋๋ค.
- ํด๋น ํ ์คํธ๋ค์ ์ ๋ถ๋ค ์คํํ๋ฉด ์๋์ ๊ฐ์ ํ์ธ์ด ๊ฐ๋ฅํฉ๋๋ค.
2. Github์ผ๋ก ํ์ธ
์ ์ฒด ํ์ผ ํ์ธ(ํ์ฌ ๋ณ๊ฒฝ๋ด์ญ)
[Github]
์ฐธ์กฐ : ์ธํ๋ฐ ๊ฐ์ [์ฅฌ์ฅฌ์ ํจ๊ป ํ๋ฃจ๋ง์ ๋๋ด๋ ์คํ๋ง ํ ์คํธ]