Ask a questionAsk a question
 

Answerbeginner tester CXXtest

  • Thursday, October 11, 2007 11:59 PMsilentHill Users MedalsUsers MedalsUsers MedalsUsers MedalsUsers Medals
     
    I've never done unit testing before and I was just suggested to get started on CXXtest tool.  I checked the official website, but I haven't found anything of how to setup the project so does anyone know CXXtesting tool and can tell me how to setup and get started?  I'm using Visual Studio 2005.

    thanks in advance..

Answers

  • Friday, October 12, 2007 1:27 AMAnonymous2342323432 Users MedalsUsers MedalsUsers MedalsUsers MedalsUsers Medals
     Answer
    Hi, go here:

    http://sourceforge.net/project/showfiles.php?group_id=52834

    Download and unzip:

    cxxtest-guide-3.10.1.pdf 

    cxxtest-3.10.1.zip

    Follow the instructions in the guide.

    You will need a c++ compiler. Get Visual Studio 2005 IDE.

    You will have to install Perl. Get that here:

    http://www.activestate.com/store/download.aspx?prdGUID=81fbce82-6bd5-49bc-a915-08d58c2648ca

    Install Perl.

    Then try "2.2 Your first test!" from the cxxtest guide.

    I had to play with the include files - changing them from #include <cxxtest/blah.h> to #include "cxxtest/blah.h"

    Not sure why, but MSVC compiler (version 12.00.81.68) didn't like the former.

    My folder structure for the first test was:

    c:\dev\cxxtest\*
    c:\dev\docs\*
    c:\dev\sample\*
    c:\dev\src\MyTestSuite.h
    c:\dev\cxxtestgen.pl

    My commands looked like:

    cd c:\dev\src
    perl -w ..\cxxtestgen.pl -w --error-printer -o runner.cpp MyTestSuite.h
    cl -GX -o runner.exe runner.cpp
    runner.exe

    Output:

    Running 1 test.OK!

    Good luck!

    Hack the Planet!

    DVSS.NET VIDEO SECURITY

    Jeff Szielenski

  • Monday, October 15, 2007 10:51 PMAnonymous2342323432 Users MedalsUsers MedalsUsers MedalsUsers MedalsUsers Medals
     Answer
    In order to generate your test source file (runner.cpp) use the following command:

    cxxtestgen.pl --runner=ParenPrinter -o runner.cpp --gui=Win32Gui mytest.h

    mytest.h contains your test class and looks something like this:

    #include <cxxtest/TestSuite.h>

    using namespace IFSPE;

    class mytest : public CxxTest::TestSuite
    {
    public:
        void test_1( void )
        {
            TS_ASSERT(1 == 1);
            Sleep(1000);
        }

        void test_2( void )
        {
            TS_ASSERT(1 + 1 > 1);
            Sleep(1000);
        }
       
        void test_3( void)
        {
            TS_ASSERT_EQUALS(1 + 1, 2);   
            Sleep(1000);       
        }
    };

    Since the --gui=Win32Gui option was specified above, when you execute runner.exe below it will start a GUI that will show real-time test status. Its pretty neat.

    Now generate your executable (runner.exe). I determined that the angle bracket "includes" (ie #include <cxxtest\Descriptions.h>) are correct and should not be changed. In order for the compiler to determine where these header files are, you must use the -I compiler option to specify the additional include directories. Also, you specify the source files to be compiled.

    Your compilation command will look something like this:

    cl -GX -I "c:\libraries\cxxtest" -I "c:\work\project1\include" -o runner.exe runner.cpp "c:\work\project1\source\mytest.cpp"

    This above command should generate your binary runner.exe.

    Now execute the test:

    runner.exe -keep

    The -keep option will keep the GUI window open until you close it.

    Good luck.

    DVSS.NET VIDEO SECURITY

    Jeff Szielenski

All Replies

  • Friday, October 12, 2007 1:27 AMAnonymous2342323432 Users MedalsUsers MedalsUsers MedalsUsers MedalsUsers Medals
     Answer
    Hi, go here:

    http://sourceforge.net/project/showfiles.php?group_id=52834

    Download and unzip:

    cxxtest-guide-3.10.1.pdf 

    cxxtest-3.10.1.zip

    Follow the instructions in the guide.

    You will need a c++ compiler. Get Visual Studio 2005 IDE.

    You will have to install Perl. Get that here:

    http://www.activestate.com/store/download.aspx?prdGUID=81fbce82-6bd5-49bc-a915-08d58c2648ca

    Install Perl.

    Then try "2.2 Your first test!" from the cxxtest guide.

    I had to play with the include files - changing them from #include <cxxtest/blah.h> to #include "cxxtest/blah.h"

    Not sure why, but MSVC compiler (version 12.00.81.68) didn't like the former.

    My folder structure for the first test was:

    c:\dev\cxxtest\*
    c:\dev\docs\*
    c:\dev\sample\*
    c:\dev\src\MyTestSuite.h
    c:\dev\cxxtestgen.pl

    My commands looked like:

    cd c:\dev\src
    perl -w ..\cxxtestgen.pl -w --error-printer -o runner.cpp MyTestSuite.h
    cl -GX -o runner.exe runner.cpp
    runner.exe

    Output:

    Running 1 test.OK!

    Good luck!

    Hack the Planet!

    DVSS.NET VIDEO SECURITY

    Jeff Szielenski

  • Friday, October 12, 2007 4:00 PMsilentHill Users MedalsUsers MedalsUsers MedalsUsers MedalsUsers Medals
     
    thank you for replying; I did read the guide in PDF form, but I couldn't find the way how to setup; maybe probably just me.  I will follow your steps and see if I can start.


  • Monday, October 15, 2007 10:51 PMAnonymous2342323432 Users MedalsUsers MedalsUsers MedalsUsers MedalsUsers Medals
     Answer
    In order to generate your test source file (runner.cpp) use the following command:

    cxxtestgen.pl --runner=ParenPrinter -o runner.cpp --gui=Win32Gui mytest.h

    mytest.h contains your test class and looks something like this:

    #include <cxxtest/TestSuite.h>

    using namespace IFSPE;

    class mytest : public CxxTest::TestSuite
    {
    public:
        void test_1( void )
        {
            TS_ASSERT(1 == 1);
            Sleep(1000);
        }

        void test_2( void )
        {
            TS_ASSERT(1 + 1 > 1);
            Sleep(1000);
        }
       
        void test_3( void)
        {
            TS_ASSERT_EQUALS(1 + 1, 2);   
            Sleep(1000);       
        }
    };

    Since the --gui=Win32Gui option was specified above, when you execute runner.exe below it will start a GUI that will show real-time test status. Its pretty neat.

    Now generate your executable (runner.exe). I determined that the angle bracket "includes" (ie #include <cxxtest\Descriptions.h>) are correct and should not be changed. In order for the compiler to determine where these header files are, you must use the -I compiler option to specify the additional include directories. Also, you specify the source files to be compiled.

    Your compilation command will look something like this:

    cl -GX -I "c:\libraries\cxxtest" -I "c:\work\project1\include" -o runner.exe runner.cpp "c:\work\project1\source\mytest.cpp"

    This above command should generate your binary runner.exe.

    Now execute the test:

    runner.exe -keep

    The -keep option will keep the GUI window open until you close it.

    Good luck.

    DVSS.NET VIDEO SECURITY

    Jeff Szielenski

  • Friday, February 06, 2009 8:20 AMAnil Kumar Sharma Users MedalsUsers MedalsUsers MedalsUsers MedalsUsers Medals
     
     Hi,

      I have to unit test for my MFC based applicaiton. When I try to include --gui=Win32GUI it throws error for "windows.h".

    Not sure this is due to that Win32GUI tries to include windows.h for MFC which is a big no no.

    Any idea to overcome this ????


    AKS
  • Sunday, September 20, 2009 7:28 PMAnil Kumar Sharma Users MedalsUsers MedalsUsers MedalsUsers MedalsUsers Medals
     Proposed Answer
    I have already resolved this a couple of months ago. The problem is in win32gui.h file that inclues the windows.h and this file is used in MFC based application. As there is a big NO for windows.h to use in MFC, so i removed windows.h from win32gui.h file that is from cxx. and includes some header files that is required to compile it properly. It worked :)
    PS:- win32gui.h is cxx header file to display the gui form report when compiled. it is included in postcompiler option in compiler as an option to use the gui for cxx. 
    AKS
  • Tuesday, October 27, 2009 9:07 AMdarya611 Users MedalsUsers MedalsUsers MedalsUsers MedalsUsers Medals
     
    helloi'm trying to integrate cxxtest with visual studio 2005 by python .
    can help me?
    thanks