关于自动化测试用例

 

在做leetcode代码时,经常碰到多种异常情况需要考虑,因此需要一个自动化的测试工具,在查找testunit是发现安装太麻烦,自己写了一个简单的测试工具:

#define  EXPECT_EQ(data0,data1)   do\

{\

    if(data0 != data1)\

       return false;\

}while(0);

bool test1()

{

    int i=0;

         EXPECT_EQ(i,1);

         return true;

 

}

bool test2()

{

     

 

     return true;

 

}

bool test3()

{

    

 

     return true;

 

}

bool test4()

{

   

 

     return true;

 

}

bool test5()

{

   

 

     return true;

 

}

class  AutoTest

{

 public:

 

   vector<bool (*)(void)> buf;

   void add()

   {

 

       // buf.push_back(test1);

        buf.push_back(test2);

        buf.push_back(test3);

        buf.push_back(test4);

        buf.push_back(test5);

 

 

   }

   void run()

   {

     vector<bool (*)(void)>::iterator ite ;

     bool ret ;

     int num=1;

     for(ite = buf.begin(); ite != buf.end(); ite++)

     {

            ret =  (*ite)();

            if(ret == false)

            {

             cout<<num<<":test fail"<<endl;

             system("pause");

            }

            else

           {

             cout<<num<<":test success"<<endl;

           }

            num++;

     }

 

   }

 

 

 

};

posted on 2014-12-18 20:54  xgcode  阅读(153)  评论(0)    收藏  举报