기본 콘텐츠로 건너뛰기

UnitTest++ 예제

■ jwFreeNote_06

6/16/2009

UnitTest++ 예제

간단한 UnitTest++ 예제이다. 다른 xUnit을 써보신 분들은 금새 알아보실 수 있을 듯.
C++은 자주 사용하는 편이 아니라서, 이렇게 메모한다는..
ps. Calculator 클래스의 구현은 반드시 해줘야 한다.-_-;

#include <UNITTEST++.H>  
      
    class Calculator  
    {  
    public:  
     Calculator();  
     ~Calculator();  
      
     int Sum(int a, int b);  
     int Sub(int a, int b);  
    };  
    struct CalculatorTestFixture  
    {  
     CalculatorTestFixture()  
     {  
      this->cal = new Calculator();  
     }  
     ~CalculatorTestFixture()  
     {  
      delete this->cal;  
     }  
      
     Calculator* cal;  
    };  
      
    TEST_FIXTURE(CalculatorTestFixture, SumTest)  
    {  
     CHECK_EQUAL(20,cal->Sum(10,10));   
    }  
      
    TEST_FIXTURE(CalculatorTestFixture, SubTest)  
    {  
     CHECK_EQUAL(0,cal->Sub(10,10));  
    }  
      
    int main()  
    {  
     UnitTest::RunAllTests();  
     getc(stdin);  
     return 1;  
    }

 
 
 
 

댓글