1 of 21

테스트 미신

강효준 Spoqa

2 of 21

테스트 그거 짜는데 오래 걸려

테스트 짜야한다고 하면 항상 듣는말

3 of 21

당장 손으로 돌려보면 되니까

$ python main.py

4 of 21

당장 손으로 돌려보면 되니까

$ python main.py

5 of 21

def abs_max(a: int, b: int) -> int:

return max(map(abs, [a, b]))

6 of 21

def abs_max(a: int, b: int) -> int:

return max(map(abs, [a, b]))

print(

abs_max(sys.argv[1], sys.argv[2])

)

7 of 21

$ python main.py 1 2

$ python main.py -1 2

$ python main.py 3 -4

8 of 21

코드(소프트웨어)는 녹이 슨다

테스트를 짜야하는 이유

9 of 21

10 of 21

구현도 복잡해지고,

라이브러리도 업데이트도 됨

팀원들이 많아지면 여러 사람이 짜야하고

11 of 21

단위 테스트

모듈, 함수, 클래스 등 특정 단위를 테스트

12 of 21

13 of 21

14 of 21

def test_abs_max():

assert abs_max(1, 2) == 2

assert abs_max(2, 3) == 3

코드를 먼저 짜고, 성공하는 케이스

15 of 21

def test_abs_max() -> None:

with raises(ValueError):

assert abs_max(None, 1)

실패하는 케이스는 나중에

16 of 21

def test_abs_max() -> None:

assert abs_max(1, 2) == 2

assert abs_max(2, 3) == 3

assert abs_max(-3, 1) == -3 #bug

버그가 생기는 케이스도 넣어보고

17 of 21

TDD

테스트를 먼저, 구현을 나중에

18 of 21

def test_abs_max() -> None:

assert abs_max(1, 2) == 2

def abs_max(a: int, b: int) -> int:

return b

19 of 21

def test_abs_max() -> None:

assert abs_max(1, 2) == 2

assert abs_max(2, 1) == 2 # fail

def abs_max(a: int, b: int) -> int:

return b

20 of 21

def test_abs_max() -> None:

assert abs_max(1, 2) == 2

assert abs_max(2, 1) == 2 # fail

def abs_max(a: int, b: int) -> int:

return max([a, b])

21 of 21

Be Spoqan,

Grow together

ed@spoqa.com