본문 바로가기
TIL/TIL

(unit test) Note: Your tests go outside the code that you're testing

by koreashowme 2020. 1. 15.

테스트할 코드는 절대 테스트를 진행하는 코드 안에 넣으시면 안 됩니다.

각 테스트는 각 함수를 "블랙 박스"처럼 다뤄야 합니다.

각 테스트는 단순히 input 값을 제공하고 assertion과 expectation만을 output 값으로 반환하는 역할을 하는 것입니다.

 

아래는 좋지 않은 예입니다:

 

function decorateClassListWithAges(classList) {

   var classListWithAges = classList.map(function(student) {

        return {'name': student, 'age': getRandomIntInclusive(10, 15)}

   });

   var checkAge = assertRange(classListWithAges[0].age, 10, 15, 'check age is between     10 and 15');

return classListWithAges;

};

comment