JUnit์ด๋ž€?

niireymikยท2024๋…„ 4์›” 8์ผ

๐Ÿ’ก
JUnit์€ Java ์—์„œ ๋…๋ฆฝ๋œ ๋‹จ์œ„ ํ…Œ์ŠคํŠธ๋ฅผ ์ง€์›ํ•ด ์ฃผ๋Š” ํ”„๋ ˆ์ž„์›Œํฌ์ด๋‹ค. ๋‹จ์œ„ ํ…Œ์ŠคํŠธ๊ฐ€ ๋ฌด์—‡์ธ์ง€ ๋จผ์ € ์•Œ์•„๋ณด๊ณ , JUnit์— ๋Œ€ํ•ด ์•Œ์•„๋ณด์ž! :>



โณ ๋‹จ์œ„ ํ…Œ์ŠคํŠธ(Unit Test) ๋ž€?

๋‹จ์œ„ ํ…Œ์ŠคํŠธ๋ž€ ํŠน์ • ์†Œ์Šค์ฝ”๋“œ์˜ ๋ชจ๋“ˆ์ด ์˜๋„ํ•œ ๋Œ€๋กœ ์ž˜ ์ž‘๋™ํ•˜๋Š”์ง€ ๊ฒ€์ฆํ•˜๋Š” ํ…Œ์ŠคํŠธ์ด๋‹ค. ์ฆ‰, ํ•จ์ˆ˜ ๋ฐ ๋ฉ”์„œ๋“œ์— ๋Œ€ํ•œ ํ…Œ์ŠคํŠธ๋ฅผ ํ•˜๋Š” ์ž‘์—…์ด๋‹ค.

ํ…Œ์ŠคํŠธ ๋Œ€์ƒ ๋‹จ์œ„๊ฐ€ ์—„๊ฒฉํ•˜๊ฒŒ ์ •ํ•ด์ ธ์žˆ์ง€๋Š” ์•Š์ง€๋งŒ, ์ผ๋ฐ˜์ ์œผ๋กœ ํด๋ž˜์Šค ๋˜๋Š” ๋ฉ”์„œ๋“œ ์ˆ˜์ค€์œผ๋กœ ์ •ํ•ด์ง„๋‹ค. ์ด๋–„ ๋‹จ์œ„์˜ ํฌ๊ธฐ๊ฐ€ ์ž‘์„์ˆ˜๋ก ๋‹จ์œ„์˜ ๋ณต์žก์„ฑ์ด ๋‚ฎ์•„์ง€๊ณ , ์‹คํ–‰ํ•˜๋ ค๋Š” ๊ธฐ๋Šฅ์„ ํ‘œํ˜„ํ•˜๊ธฐ ๋” ์‰ฌ์›Œ์ง„๋‹ค.

๋‹จ์œ„ ํ…Œ์ŠคํŠธ์˜ ์žฅ์ 

  • ํ•ด๋‹น ๋ถ€๋ถ„๋งŒ ๋…๋ฆฝ์ ์œผ๋กœ ํ…Œ์ŠคํŠธํ•˜๊ธฐ ๋•Œ๋ฌธ์— ์–ด๋–ค ์ฝ”๋“œ๋ฅผ ๋ฆฌํŒฉํ† ๋งํ•˜์—ฌ๋„ ๋น ๋ฅด๊ฒŒ ๋ฌธ์ œ ์—ฌ๋ถ€๋ฅผ ํŒŒ์•…ํ•  ์ˆ˜ ์žˆ๋‹ค.
  • ๊ฐœ๋ฐœ์ž๋Š” ์ž‘์„ฑํ•œ ํ…Œ์ŠคํŠธ ์ฝ”๋“œ๋ฅผ ์ˆ˜์‹œ๋กœ ๋น ๋ฅด๊ฒŒ ๋Œ๋ฆฌ๋ฉด์„œ ๋ฌธ์ œ์ ์„ ํŒŒ์•…ํ•  ์ˆ˜ ์žˆ๋‹ค.


JUnit ์ด๋ž€?

์ž๋ฐ” ๊ฐœ๋ฐœ์ž๊ฐ€ ๊ฐ€์žฅ ๋งŽ์ด ์‚ฌ์šฉํ•˜๋Š” ํ…Œ์ŠคํŒ… ๊ธฐ๋ฐ˜ ํ”„๋ ˆ์ž„์›Œํฌ๋กœ์„œ, ํ•˜๋‚˜์˜ jar ํŒŒ์ผ๋กœ ๋˜์–ด ์žˆ๋‹ค.

ํ…Œ์ŠคํŠธ ๊ฒฐ๊ณผ๋ฅผ ๋ฌธ์„œ๋กœ ๋‚จ๊ธฐ๋Š” ๊ฒƒ์ด ์•„๋‹ˆ๋ผ Test Class ์ž์ฒด๋ฅผ ๋‚จ๊ธฐ๊ธฐ์—, ์†Œ์Šค์ฝ”๋“œ๋ฅผ ์ˆ˜์ •ํ•ด๋„ ํ•ด๋‹น ์ฝ”๋“œ๊ฐ€ ์ œ๋Œ€๋กœ ๋™์ž‘ํ•˜๋Š”์ง€ ํ…Œ์ŠคํŠธ ์ฝ”๋“œ๋ฅผ ๊ฐ€์ง€๊ณ  ๊ทธ๋Œ€๋กœ ํ…Œ์ŠคํŠธ ํ•  ์ˆ˜๋„ ์žˆ๊ณ , ๋‹ค๋ฅธ ๊ฐœ๋ฐœ์ž์—๊ฒŒ ํ…Œ์ŠคํŠธ ๋ฐฉ๋ฒ• ๋ฐ ํด๋ž˜์Šค์˜ histroy๋ฅผ ๋„˜๊ฒจ์ค„ ์ˆ˜๋„ ์žˆ๋‹ค.

JUnit์€ ์—ฌ๋Ÿฌ ๋ฒ„์ „์ด ์žˆ์œผ๋ฉฐ, ํ˜„์žฌ ๊ฐ€์žฅ ๋งŽ์ด ์‚ฌ์šฉ๋˜๊ณ  ์žˆ๋Š” ๋ฒ„์ „์€ JUnit 5์ด๋‹ค. ๊ธฐ๋ณธ Junit 4์— ๋น„ํ•ด JUnit 5๋Š” 3๊ฐ€์ง€ ๋ชจ๋“ˆ๋กœ ๊ตฌ์„ฑ๋˜์–ด ์žˆ์œผ๋ฉฐ, JUnit5๋Š” ํ…Œ์ŠคํŠธ ์ž‘์„ฑ์ž๋ฅผ ์œ„ํ•œ API ๋ชจ๋“ˆ๊ณผ ํ…Œ์ŠคํŠธ ์‹คํ–‰์„ ์œ„ํ•œ API๊ฐ€ ๋ถ„๋ฆฌ๋˜์–ด ์žˆ๋‹ค.

JUnit4๋ถ€ํ„ฐ๋Š” @ ์–ด๋…ธํ…Œ์ด์…˜์„ ์ง€์›ํ•˜์—ฌ ๊ฐ„๋‹จํ•˜๊ฒŒ ํ…Œ์ŠคํŠธํ•  ์ˆ˜ ์žˆ๋Š” ํ™˜๊ฒฝ์„ ์ œ๊ณตํ•œ๋‹ค.


JUnit5

๊ตฌ์กฐ

JUnit5๋Š” ํฌ๊ฒŒ 3๊ฐ€์ง€ ๋ชจ๋“ˆ๋กœ ๊ตฌ์„ฑ๋œ๋‹ค.

JUnit5 = JUnit Platform + JUnit Jupiter + JUnit Vintage

  • JUnit Platform : ํ…Œ์ŠคํŠธ๋ฅผ ๋ฐœ๊ฒฌํ•˜๊ณ  ํ…Œ์ŠคํŠธ ๊ณ„ํš์„ ์ƒ์„ฑํ•˜๋Š” TestEngine ์ธํ„ฐํŽ˜์ด์Šค๋ฅผ ๊ฐ€์ง€๊ณ  ์žˆ๋‹ค. ์ฆ‰, Platform์€ TestEngine์„ ํ†ตํ•ด์„œ ํ…Œ์ŠคํŠธ๋ฅผ ๋ฐœ๊ฒฌํ•˜๊ณ  ์‹คํ–‰ํ•˜๊ณ  ๊ฒฐ๊ณผ๋ฅผ ๋ณด๊ณ ํ•œ๋‹ค.

  • JUnit Jupiter : TestEngine์˜ ์‹ค์ œ ๊ตฌํ˜„์ฒด๋Š” ๋ณ„๋„ ๋ชจ๋“ˆ์ธ๋ฐ, ๊ทธ์ค‘ ํ•˜๋‚˜์ด๋‹ค. JUnit5์—์„œ ์ƒˆ๋กญ๊ฒŒ ์ถ”๊ฐ€๋œ ๊ฒƒ์ด ๋ฐ”๋กœ Jupiter API์ด๊ณ , ์ด๋ฅผ JUnit5์—์„œ๋Š” ์ด๋ฅผ ์‚ฌ์šฉํ•ด ํ…Œ์ŠคํŠธ ์ฝ”๋“œ๋ฅผ ๋ฐœ๊ฒฌํ•˜๊ณ  ์‹คํ–‰ํ•œ๋‹ค.

  • JUnit Vintage : JUnit3, JUnit4 ๋ฅผ ์‹คํ–‰ํ•  ์ˆ˜ ์žˆ๋Š” TestEngine ์ด๋‹ค. ํ•˜์œ„ ํ˜ธํ™˜์„ฑ์„ ์œ„ํ•ด์„œ ์กด์žฌํ•œ๋‹ค. Jupiter์™€ ๋™์ผํ•˜๊ฒŒ, TestEngine์˜ ์‹ค์ œ ๊ตฌํ˜„์ฒด ๋ชจ๋“ˆ ์ค‘ ํ•˜๋‚˜์— ํ•ด๋‹นํ•œ๋‹ค.

-> ์ฆ‰, JUnit Platform์€ ์ „๋ฐ˜์ ์ธ ํ…Œ์ŠคํŠธ API๋“ค์„ ์ œ๊ณตํ•˜๊ณ  ์žˆ๊ณ  ์ด๋ฅผ ๊ตฌํ˜„ํ•œ Jupiter์™€ Vintage๊ฐ€ ์กด์žฌํ•œ๋‹ค๊ณ  ๋ณผ ์ˆ˜ ์žˆ๋‹ค. JUnit5๋Š” Java 8๋ฒ„์ „ ์ด์ƒ์ด ํ•„์š”ํ•˜๋‹ค.

Annotations

์•ž์„œ ์–ธ๊ธ‰ํ–ˆ๋“ฏ, Test ์—ญ์‹œ ์ž๋ฐ”์˜ ๊ฐ์ฒด๋กœ ๊ตฌ์„ฑ๋œ๋‹ค.
๋”ฐ๋ผ์„œ ํด๋ž˜์Šค๋กœ ๊ตฌํ˜„์„ ํ•˜๊ธฐ ๋•Œ๋ฌธ์— ํด๋ž˜์Šค ๋‚ด๋ถ€์— ๋ฉ”์„œ๋“œ๊ฐ€ ํฌํ•จ๋˜๋Š” ํ˜•ํƒœ์ด๋‹ค.

Test์— ์‚ฌ์šฉ๋˜๋Š” ์–ด๋…ธํ…Œ์ด์…˜์€ ๋‹ค์Œ๊ณผ ๊ฐ™์ด ๊ตฌ๋ถ„ ์ง€์–ด ๋ณผ ์ˆ˜ ์žˆ๋‹ค.

+Test Class ๋Š” absctract ์ด๋ฉด ์•ˆ๋˜๋ฉฐ, ๊ธฐ๋ณธ ์ƒ์„ฑ์ž๋ฅผ ํฌํ•จํ•ด์•ผ ํ•œ๋‹ค!

Class

  • @Nested : static์ด ์•„๋‹Œ ์ค‘์ฒฉ ํ…Œ์ŠคํŠธ ํด๋ž˜์Šค์ž„์„ ์•Œ๋ฆฌ๋Š” ์–ด๋…ธํ…Œ์ด์…˜
    ํด๋ž˜์Šค ๋ณ„ ํ…Œ์ŠคํŠธ ์ธ์Šคํ„ด์Šค lifecycle์„ ์‚ฌ์šฉํ•˜์ง€ ์•Š๋Š” ํ•œ @BeforeAll , @AfterAll ๋ฉ”์„œ๋“œ์—์„œ๋Š” ์‚ฌ์šฉ์ด ๋ถˆ๊ฐ€ํ•˜๋‹ค.

Test Method

  • @Test : ํ•ด๋‹น ๋ฉ”์„œ๋“œ๊ฐ€ ํ…Œ์ŠคํŠธ ๋ฉ”์„œ๋“œ์ž„์„ ๋‚˜ํƒ€๋‚ธ๋‹ค.
  • @ParametherizedTest : ํ•ด๋‹น ๋ฉ”์„œ๋“œ๊ฐ€ ๋งค๊ฐœ๋ณ€์ˆ˜๊ฐ€ ์žˆ๋Š” ํ…Œ์ŠคํŠธ์ž„์„ ๋‚˜ํƒ€๋‚ธ๋‹ค.
  • @RepeatedTest : ๋ฐ˜๋ณต ํšŸ์ˆ˜๋งŒํผ ํ…Œ์ŠคํŠธ๋ฅผ ๋ฐ˜๋ณตํ•œ๋‹ค. -> @RepeatedTest(3)

LifeCycle Mothod

  • @BeforeAll : ํ…Œ์ŠคํŠธ Class ๊ธฐ์ค€์œผ๋กœ ํ…Œ์ŠคํŠธ ๋ฉ”์„œ๋“œ๋“ค์ด ์‹คํ–‰๋˜๊ธฐ ์ „ ์‹คํ–‰ํ•œ๋‹ค. (์ฆ‰, ํ…Œ์ŠคํŠธ ์‹œ์ž‘ ์‹œ์ ์— ๋”ฑ ํ•œ๋ฒˆ ์‹คํ–‰)
  • @BeforeEach : ๊ฐ ํ…Œ์ŠคํŠธ ๋ฉ”์„œ๋“œ๊ฐ€ ์‹คํ–‰๋˜๊ธฐ ์ „ ์‹คํ–‰ํ•œ๋‹ค.
  • @AfterAll : ํ…Œ์ŠคํŠธ Class ๊ธฐ์ค€์„ ํ…Œ์ŠคํŠธ ๋ฉ”์„œ๋“œ๋“ค์ด ์‹คํ–‰๋œ ํ›„ ์‹คํ–‰ํ•œ๋‹ค. (์ฆ‰, ํ…Œ์ŠคํŠธ ์ข…๋ฃŒ ์‹œ์ ์— ๋”ฑ ํ•œ ๋ฒˆ ์‹คํ–‰)
  • @AfterEach : ๊ฐ ํ…Œ์ŠคํŠธ ๋ฉ”์„œ๋“œ๊ฐ€ ์‹คํ–‰๋˜๊ธฐ ์ „ ์‹คํ–‰

โœ… BeforeAll โ†’ [ BeforeEach โ†’ Test โ†’ AfterEach ] โ†’ AfterAll

๊ธฐํƒ€ ์–ด๋…ธํ…Œ์ด์…˜

  • @Tag : ํ…Œ์ŠคํŠธ ๊ฒ€์ƒ‰ ๋ฐ ์‹คํ–‰์„ ํ•„ํ„ฐ๋งํ•  ์ˆ˜ ์žˆ๋Š” ํ…Œ์ŠคํŠธ ํ•„ํ„ฐ๋ง์„ ์œ„ํ•œ ํƒœ๊ทธ์ž„์„ ์•Œ๋ฆฌ๋Š”๋ฐ ์‚ฌ์šฉ๋œ๋‹ค.
  • @Disabled : ํ•ด๋‹น ํด๋ž˜์Šค๋‚˜ ํ…Œ์ŠคํŠธ๋ฅผ ์‹คํ–‰ํ•˜์ง€ ์•Š๋Š”๋‹ค.
  • @Timeout : ํ…Œ์ŠคํŠธ ์‹คํ–‰ ์‹œ๊ฐ„ ์„ ์–ธ, ์ดˆ๊ณผ๋˜๋ฉด ์‹คํŒจํ•˜๋„๋ก ์„ค์ •ํ•œ๋‹ค.
  • @TempDir : ํ•„๋“œ ์ฃผ์ž…, ๋งค๊ฐœ๋ณ€์ˆ˜ ์ฃผ์ž…์„ ํ†ตํ•ด ์ž„์‹œ ๋””๋ ‰ํ† ๋ฆฌ๋ฅผ ์ œ๊ณตํ•˜๋Š” ๋ฐ ์‚ฌ์šฉ๋œ๋‹ค.
  • @DisplayName : ํ…Œ์ŠคํŠธ ํด๋ž˜์Šค ๋˜๋Š” ํ…Œ์ŠคํŠธ ๋ฉ”์„œ๋“œ์— ์ง์ ‘ ์ด๋ฆ„์„ ์ง€์ •ํ•œ๋‹ค.

Assertions

  • assertArrayEquals(a, b)
    : ๋ฐฐ์—ด A์™€ B๊ฐ€ ์ผ์น˜ํ•จ์„ ํ™•์ธ
  • assertEquals(a, b)
    : ๊ฐ์ฒด A์™€ B๊ฐ€ ๊ฐ™์€ ๊ฐ’์„ ๊ฐ€์ง€๋Š”์ง€ ํ™•์ธ
  • assertEquals(a, b, c)
    : ๊ฐ์ฒด A์™€ B๊ฐ€ ๊ฐ’์ด ์ผ์น˜ํ•จ์„ ํ™•์ธ( a: ์˜ˆ์ƒ ๊ฐ’, b:๊ฒฐ๊ด๊ฐ’, c: ์˜ค์ฐจ ๋ฒ”์œ„)
  • assertSame(a, b)
    : ๊ฐ์ฒด A์™€ B๊ฐ€ ๊ฐ™์€ ๊ฐ์ฒด์ž„์„ ํ™•์ธ
  • assertTrue(a)
    : ์กฐ๊ฑด A๊ฐ€ ์ฐธ์ธ์ง€ ํ™•์ธ
  • assertNotNull(a)
    : ๊ฐ์ฒด A๊ฐ€ null์ด ์•„๋‹˜์„ ํ™•์ธ


๐Ÿ“ ์ •๋ฆฌํ•˜๊ธฐ
JUnit์€ Java์—์„œ ๋…๋ฆฝ๋œ ๋‹จ์œ„ ํ…Œ์ŠคํŠธ๋ฅผ ์ง€์›ํ•ด ์ฃผ๋Š” ํ”„๋ ˆ์ž„์›Œํฌ์ด๋‹ค๐Ÿ˜บ

1๊ฐœ์˜ ๋Œ“๊ธ€

comment-user-thumbnail
2025๋…„ 8์›” 27์ผ

https://www.globhy.com/article/buying-horizontal-carbonized-bamboo-flooring-from-china-while-living-in-new-york
https://www.globhy.com/article/why-bamboo-flooring-is-the-eco-friendly-champion-of-sustainable-homes
https://www.hentai-foundry.com/user/bothbest/blogs/20350/Choosing-Bamboo-Flooring-for-My-London-Home
https://yamap.com/users/4784209
https://forum.iscev2024.ca/member.php?action=profile&uid=1357
https://my.usaflag.org/members/bothbest/profile/
https://myliveroom.com/bothbest
https://forum.geckos.ink/member.php?action=profile&uid=642
https://competitorcalendar.com/members/bothbest/profile/
https://www.fruitpickingjobs.com.au/forums/users/bothbest/
https://thefwa.com/profiles/bamboo-flooring
https://chanylib.ru/ru/forum/user/9508/
https://greenteam.app/bothbest
http://www.v0795.com/home.php?mod=space&uid=2304271
https://wearedevs.net/profile?uid=201358
https://www.templepurohit.com/forums/users/chinahousehold/
https://tutorialslink.com/member/FlooringBamboo/68089
https://www.tkaraoke.com/forums/profile/bothbest/
https://www.aipictors.com/users/bothbest
https://forum.index.hu/User/UserDescription?u=2129081
http://programujte.com/profil/75582-chinabamboo/
https://lamsn.com/home.php?mod=space&uid=1290622
https://nexusstem.co.uk/community/profile/chinabamboo/
https://brain-market.com/u/chinabamboo
https://malt-orden.info/userinfo.php?uid=414587
https://www.halaltrip.com/user/profile/255692/chinabamboo/
https://goodgame.ru/user/1698091
https://vcook.jp/users/42177
https://library.zortrax.com/members/china-bamboo/
https://aprenderfotografia.online/usuarios/chinabamboo/profile/
https://plaza.rakuten.co.jp/chinabamboo/
https://plaza.rakuten.co.jp/chinabamboo/diary/202508270000/
https://plaza.rakuten.co.jp/chinabamboo/diary/202508270001/
https://eternagame.org/players/538402
https://www.slmath.org/people/82724
https://www.aipictors.com/users/chinabambooflooring
https://vocal.media/authors/china-bamboo-bfc
https://www.giantbomb.com/profile/chinabamboo/
https://www.keedkean.com/member/44724.html?type=profile

๋‹ต๊ธ€ ๋‹ฌ๊ธฐ