Skip to content

Latest commit

ย 

History

History
70 lines (45 loc) ยท 3.08 KB

File metadata and controls

70 lines (45 loc) ยท 3.08 KB

โ€œThere is no secret to writing testsโ€ฆโ€ฆ there are only secrets to writing testable code!โ€

  • ํ…Œ์ŠคํŠธ ์ž‘์„ฑ์— ๋Œ€ํ•ด์„œ๋Š” ๋น„๋ฒ•์ด ์—†๋‹ค.
  • ํ…Œ์ŠคํŠธ ๊ฐ€๋Šฅํ•œ ์ฝ”๋“œ๋ฅผ ์ž‘์„ฑํ•˜๋Š” ๋น„๋ฒ•๋งŒ์ด ์กด์žฌํ•œ๋‹ค.
    • Good OO
    • Dependency Injection(Inversion)
    • Test Driven Development

Progression of Testing

Stage 1: Scenario Tests

โ€œTest the whole app as unit by pretending to be a userโ€

  • ์‚ฌ์šฉ์ž์ฒ˜๋Ÿผ ๋Œ€์ƒ ์–ดํ”Œ๋ฆฌ์ผ€์ด์…˜์„ ํ•˜๋‚˜์˜ ํ…Œ์ŠคํŠธ ๋Œ€์ƒ ๋‹จ์œ„๋กœ ์ฒ˜๋ฆฌํ•˜๋Š” ํ”„๋ ˆ์ž„์›Œํฌ๋ฅผ ๋งŒ๋“œ๋Š” ๋ฐฉ๋ฒ• โ€“ โ€œScenario/Large Testsโ€
  • ํ…Œ์ŠคํŠธ๊ฐ€ ๋А๋ฆฌ๋‹ค. ๊ทธ๋ž˜์„œ ๊ฐœ๋ฐœ์ž๋“ค์ด ์ˆ˜ํ–‰ํ•˜์ง€ ์•Š๋Š”๋‹ค.
  • ํ…Œ์ŠคํŠธ๊ฐ€ Flakyํ•˜๋‹ค.
    • Because you test the real app with real external dependencies sometimes things take a bit longer than expected and you get false negatives.

Stage 2: Functional Tests

โ€œFunctional/Medium Testsโ€

  • ์• ํ”Œ๋ฆฌ์ผ€์ด์…˜์„ ์„œ๋ธŒ์‹œ์Šคํ…œ์œผ๋กœ ๋ถ„ํ•ดํ•˜๊ณ  ์™ธ๋ถ€ ์˜์กด์„ฑ์„ simulator๋กœ ์น˜ํ™˜ํ•ด์„œ ๊ฐ ์„œ๋ธŒ์‹œ์Šคํ…œ์„ ํ…Œ์ŠคํŠธ
  • ์‹œ๋‚˜๋ฆฌ์˜ค ํ…Œ์ŠคํŠธ์—์„œ๋Š” ๋ถˆ๊ฐ€ํ•œ ์กฐ๊ฑด์„ ์‹œ๋ฎฌ๋ ˆ์ดํŠธํ•  ์ˆ˜ ์žˆ์Œ
  • ๊ฐœ๋ฐœ์ž๋“ค์€ ์ด ํ…Œ์ŠคํŠธ๋ฅผ ์ฝ”๋“œ๋ฅผ ์ œ์ถœ(commit, PR, merge ๋“ฑ) ์ „์— ์‹คํ–‰ํ•ด ๋ณผ ์ˆ˜ ์žˆ์Œ

Stage 3: Unit Tests

โ€œUnit/Small Testsโ€

  • ์ž‘์€ ์˜์—ญ์˜ ์ฝ”๋“œ๋ฅผ ํ…Œ์ŠคํŠธํ•˜๋Š” ๊ฒƒ์€ ๋งŽ์€ ํ˜œํƒ์„ ์ฃผ๋ฏ€๋กœ ํ…Œ์ŠคํŠธ ๋‹จ์œ„๋ฅผ ๋” ์ž‘์€ ๋‹จ์œ„๋กœ ๋‚˜๋ˆŒ ์ˆ˜ ์žˆ์Œ
  • ๊ฐ ํด๋ž˜์Šค๋ฅผ ๊ฒฉ๋ฆฌํ•˜์—ฌ ํ…Œ์ŠคํŠธ
  • ๋ชจ๋“  ์˜ค๋ฅ˜ ์กฐ๊ฑด๋“ค์„ ์‹œ๋ฎฌ๋ ˆ์ดํŠธํ•  ์ˆ˜ ์žˆ์Œ
  • ๊ฐœ๋ฐœ์ž๋“ค์€ ํŒŒ์ผ์„ ์ˆ˜์ •ํ•  ๋•Œ๋งˆ๋‹ค ๋‹จ์œ„ ํ…Œ์ŠคํŠธ๋ฅผ ์‹คํ–‰ํ•  ์ˆ˜ ์žˆ์Œ
  • ๋นจ๋ฆฌ ๋น ๋ฅด๊ณ  ํ…Œ์ŠคํŠธ๊ฐ€ ๊นจ์งˆ ํ™•๋ฅ ์ด ์ ์Œ
Test Type Definition Issues
Scenario / Large Tests Test whole application by pretending to be a user Slow / Flaky / Mostly happy paths
Functional / Medium Tests External dependencies simulated Test class interaction
Unit / Small Tests Focus on application logic Very Fast / No I/O / No need for a debugger

Different Kinds of Tests

Unit Testing a Class

  • ํ…Œ์ŠคํŠธ ์ฝ”๋“œ ์ž‘์„ฑ์ด ์–ด๋ ค์›Œ์ง„ ์ด์œ 
    • ๊ฐ์ฒด ์ƒ์„ฑ ์ฝ”๋“œ์™€ ๋น„์ง€๋‹ˆ์Šค ๋กœ์ง์„ ํ˜ผํ•ฉํ•ด์„œโ€ฆ
    • ์ด๋กœ ์ธํ•ด ํ…Œ์ŠคํŠธ๋Š” ์šด์˜ํ™˜๊ฒฝ๊ณผ ๋‹ค๋ฅธ ๊ฐ์ฒด ๊ทธ๋ž˜ํ”„๋ฅผ ๋งŒ๋“ค ์ˆ˜ ์—†๊ฒŒ ๋˜๊ณ , ๊ณ ๋ฆฝ๋œ(isolated) ์ƒํƒœ์—์„œ ํ…Œ์ŠคํŠธ ํ•  ์ˆ˜ ์—†๊ฒŒ ๋˜์—ˆ๋‹ค.

Take Away

  • Unit Tests are a preferred way of testing
  • Unit Tests require separation of Instantiation of Object Graph from Business Logic under test