โThere is no secret to writing testsโฆโฆ there are only secrets to writing testable code!โ
- ํ ์คํธ ์์ฑ์ ๋ํด์๋ ๋น๋ฒ์ด ์๋ค.
- ํ
์คํธ ๊ฐ๋ฅํ ์ฝ๋๋ฅผ ์์ฑํ๋ ๋น๋ฒ๋ง์ด ์กด์ฌํ๋ค.
- Good OO
- Dependency Injection(Inversion)
- Test Driven Development
โ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.
โFunctional/Medium Testsโ
- ์ ํ๋ฆฌ์ผ์ด์ ์ ์๋ธ์์คํ ์ผ๋ก ๋ถํดํ๊ณ ์ธ๋ถ ์์กด์ฑ์ simulator๋ก ์นํํด์ ๊ฐ ์๋ธ์์คํ ์ ํ ์คํธ
- ์๋๋ฆฌ์ค ํ ์คํธ์์๋ ๋ถ๊ฐํ ์กฐ๊ฑด์ ์๋ฎฌ๋ ์ดํธํ ์ ์์
- ๊ฐ๋ฐ์๋ค์ ์ด ํ ์คํธ๋ฅผ ์ฝ๋๋ฅผ ์ ์ถ(commit, PR, merge ๋ฑ) ์ ์ ์คํํด ๋ณผ ์ ์์
โ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 |
- ํ
์คํธ ์ฝ๋ ์์ฑ์ด ์ด๋ ค์์ง ์ด์
- ๊ฐ์ฒด ์์ฑ ์ฝ๋์ ๋น์ง๋์ค ๋ก์ง์ ํผํฉํด์โฆ
- ์ด๋ก ์ธํด ํ ์คํธ๋ ์ด์ํ๊ฒฝ๊ณผ ๋ค๋ฅธ ๊ฐ์ฒด ๊ทธ๋ํ๋ฅผ ๋ง๋ค ์ ์๊ฒ ๋๊ณ , ๊ณ ๋ฆฝ๋(isolated) ์ํ์์ ํ ์คํธ ํ ์ ์๊ฒ ๋์๋ค.
- Unit Tests are a preferred way of testing
- Unit Tests require separation of Instantiation of Object Graph from Business Logic under test