0%

Testing

Testing

Testing 은 Shipping (배포) 보다 중요하다.

만약 테스트가 없거나 적절하지 않은 양만큼 (부족한) 만 존재할 경우, 배포할 때마다 코드를 break 했는지 혹은 수정한 코드가 올바르게 작동할지 확신할 수 없다.

적절한 양을 정하는 요소는 팀과 상황에 따라 다르지만, 100%의 Coverage ( 보호 범위 , 즉, 모든 statement와 branch가 보호됨) 를 갖는 것은 개발 시에 안전함과 자신감을 제공한다.

따라서, testing framework 에 더하여 good coverage tool 또한 필요 하다.

e.g.

Testing Framework : Mocha · QUnit · Jasmine · Karma · Intern · AVA, etc.

Coverage Tool : istanbul · Cobertura · CodeCover · Coverage.py · EMMA, etc.


Test Driven Development (TDD)

  • 모든 feature / module 에 대한 테스트를 정의하자.
  • 목표 coverage 를 도달한 상태에서 새로운 feature을 배포하자.
    • 도달하지 못했다면, refactoring 부터 하자.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
import assert from "assert";

// bad
describe("MomentJS", () => {
// date boundary를 ☹️한 데 모아😡 처리함.
it("handles date boundaries", () => {
let date;

date = new MomentJS("1/1/2015");
date.addDays(30);
assert.equal("1/31/2015", date);

date = new MomentJS("2/1/2016");
date.addDays(28);
assert.equal("02/29/2016", date);

date = new MomentJS("2/1/2015");
date.addDays(28);
assert.equal("03/01/2015", date);
});
});

// good
describe("MomentJS", () => {
// date boundary handler를 😄여러 조건으로 나누어🤩 정의함.

// 30일을 가진 month 의 경우
it("handles 30-day months", () => {
const date = new MomentJS("1/1/2015");
date.addDays(30);
assert.equal("1/31/2015", date);
});

// 윤년의 경우
it("handles leap year", () => {
const date = new MomentJS("2/1/2016");
date.addDays(28);
assert.equal("02/29/2016", date);
});

// 그 외, 31일을 가진 month && 윤년이 아닌 경우
it("handles non-leap year", () => {
const date = new MomentJS("2/1/2015");
date.addDays(28);
assert.equal("03/01/2015", date);
});
});