소프트웨어공학 (Software Engineering)

단위 테스트, Unit testing

깡또아빠 2022. 5. 4. 19:31

단위 테스트 (Unit testing)은 설계된 모듈이 정확히 구현되었는지 확인하고, 모듈과 같은 하나의 소프트웨어 구성요소나 소프트웨어 구성요소의 집합이 프로그램의 요구사항에 맞는지 확인하는 테스팅 [IEEE 1012-1998 VVP]

 

Testing conducted to verify the correct implementation of the design and compliance with program requirements for one software element (e.g., unit, module) or a collection of software elements.

 

단위 테스트 (Unit testing)에 한해서는 결함 발견의 목적 보다는 기능의 정상 동작을 확인하는 것이 더 중요합니다. 개발자(Engineer) 가 모듈이 올바르게 코딩되었는지 확인하기 때문입니다. 

 

단위 테스트 시 단독으로/분리되어 테스팅 할 수 있는 환경이 필요 합니다. 

아래와 같이 Test driver, Stub (or mocking) 그림을 통해서 단위 테스트를 설명해 보면,

 

테스팅 드라이버(Test Driver): 테스팅 대상 모듈을 호출하는 환경

스텁 (Stub) 또는 Mocking: 테스팅 대상 모듈에서 호출하는 모듈

 

테스팅 대상 모듈 (Testing Module)을 단위 테스트 하면서 결함이 발견되면, 스텁 (Stub), Mocking이 아닌 테스팅 대상 모듈에 한정해서 원인을 찾아야 합니다. 그러기 위해서 Stub에서는 Constant value 로 고정해서 활용합니다. 

 

테스팅 대상 모듈을 호출하는 경우 테스팅 드라이버라고 부릅니다. 

 

Stub, Driver의 차이점은 아래를 참고하시기 바랍니다.

 

Stub

  • Stubs are created in the integration testing that is following a Top-down approach.
  • A stub is a piece of code emulating a called function. A stub is created by the tester when high-level modules are being tested and the other modules are not yet created. Overall testing is only possible when all the modules are present and dummy modules have to be created to replicate basic functionality of modules under construction.
  • A stub is basically a piece of code that simulates the activity of missing modules. I just accept the value from the calling module and returns a null value.

 

Driver:

  • A driver is a piece of code which is emulating a calling function. Basically, we call the driver as the main function which calls other modules to form complete applications.
  • Drivers are created in integration testing following a bottom-up approach. Dummy main function has been created which will call other submodules.
  • A piece of code that passes test cases to another piece of code. Drivers invoke modules under testing.

 

One simple way to remember the difference in stubs and drivers is to remember drivers are “calling” function while stubs are “called” functions.

 

감사합니다.