Help adding test cases

Jul 3, 2011 at 1:26 PM

Hi

I am trying to find a good unit testing framework for applications developed using native c++ and i found this tool to suit my requirement.

I have installed the addin and the written a sample c++ app with 2 functions namely ADD and SUB which returns the sum/difference respectively.

I  wanted to know, how to add test cases for the same. I tried a simple test as given below:

//myapptest1.cpp

void MyAppTest::AddTest()

{

    //UT_ASSERT2(FALSE, L"not implemented");
    MyApp *obj = new MyApp;
    int a = 10;
    int b = 20;

    UT_ASSERT2((obj->Add(a,b) < 0), L"Sum less than 0"); // Line 30

    delete(obj);

}

I am getting the following exception when i run the test case from test runner.

---------------------------
Microsoft Visual C++ Debug Library
---------------------------
Debug Assertion Failed!

Program: MyApplication\MyApp\UnitTest\Debug\MyAppTest.exe
File: projects\myapplication\myapp\unittest\myapptest1.cpp
Line: 30

Expression: __b_tempvr

For information on how your program can cause an assertion
failure, see the Visual C++ documentation on asserts.

(Press Retry to debug the application)
---------------------------
Abort   Retry   Ignore  
---------------------------

Please correct me if i am wrong.

 

Coordinator
Jul 4, 2011 at 7:13 PM

 

I would not recommend you to use this framework because there is no time for me to develop the add- in.

About your code

UT_ASSERT and UT_ASSERT2 work as ATLASSERT aka condition has to be TRUE - that means the check has succeeded otherwise you as developer has to fix your code or testcase so the condition has to be TRUE.

In your case (obj->Add(a,b) < 0) I suppose the code looks like a + b < 0 if a = 10 b = 20 than 30 < 0  this is FALSE.

I guess you want to write UT_ASSERT2((obj->Add(a,b) == 30), L"Sum has to be 30"); // Line 30

Jul 5, 2011 at 2:19 AM

Thank you for your reply.

I was hoping to use this tool for unit testing. It has been done nicely though.

Could you suggest me any other unit testing framework which you might have come across for native c++ applications?

I am currently trying out cfix, Google C++ unit testing framework.

Coordinator
Jul 5, 2011 at 5:57 PM

 

There are also boost http://www.boost.org/doc/libs/1_46_1/libs/test/doc/html/index.html

cppunit http://sourceforge.net/apps/mediawiki/cppunit/index.php?title=Main_Page

Suppose you can choose any framework. My advise is to start with one that takes less that one day to start working with.