[CMake] CTest examples

Bo Thorsen bo at askmonty.org
Mon Jul 12 07:23:33 EDT 2010


Den 09-07-2010 19:03, Eric Noulard skrev:
> 2010/7/9 Bo Thorsen<bo at askmonty.org>:
>> Hi people,
>>
>> I have converted a set of applications to cmake and cpack, and now have my
>> eyes set on ctest.
>>
>> I'd like to hear if someone here has some good advice, or links to good
>> advice, on how to structure tests. I'm searching for help on how to put
>> different tests into what executables. On how to handle multiple tests on
>> each classes, on how to best structure the test of the static libraries (all
>> of those are part of the source tree) that are linked in to the application.
>> And on how to test classes from the main application itself.
>>
>> I have read the ctest FAQ, documentation etc. and still don't know anything
>> that help me write the actual test code.
>>
>>  From the looks of it, ctest only provides the framework to run a test, no
>> help is given to write the code of the tests themselves, is this right? I
>> have previously been using cppunit, and it looks like this will still be
>> useful.
>
> Yes you are right.
> CTest is helping for running tests using "Test Driver".
> CTest is useful for continuous integration if you use it with CDash
> and for that part (from my point of view) it's useful if do not have
> test at all, because you may monitor build breakage on various platform.
>
> It helps even more if the tests application (which may be written using cppunit)
> is built using CMake and/or is linked with the library your are
> building (with CMake ...)
>
> in an
> add_test(NAME TestName
>                COMMAND  TestProg)
>
> TestProg (the Test Driver) may be built from an
> add_executable(TestProg TestProg.c)
> target_link_libraries(TestProg TheTestedLib)
>
> or it may be a custom script (Python or anything you like)
> or it may be a custom script which has been "configured" at CMake
> time using configure_file....
>
>> To sum it up, I'm looking for real life advice on what you guys have done
>> with ctest. This information seem almost completely missing on the net,
>> where all searches on ctest leads to useless presentation on ctest features.
>
> Real life usually depends on your life but...
> Speaking for myself on two small projects (C and/or C++) I do use
> simple (C or C++) test driver applications for basic unit test and
> some python scripts for integration tests.
>
> My [compiled C/C++] test drivers simply return 0 if the test is
> successfull and something
> else if not. CTest understand that out-of-the-box which makes it easy to see
> unit test breakage using a simple "make test".
>
> My Python script is driving several interacting applications (from 2 up to 10)
> which are part of the build, in the same way the python script return non zero
> value on error.
>
> Since the whole testsuite may be running for a long time I'm using CTest
> during development in order to easily select test to be run on a particular area
> using
>
> ctest -R<regex>  = Run tests matching regular expression.
>
> I have my own naming rules for tests name which makes it easy to use.
>
> I'm not using any unit test framework but I think there has already been some
> discussion about mixed CMake/CTest CppUnit usage on this list.
>
> Now I really cannot ensure that those advices will be as good
> for you as they are too me :-)

It is certainly helpful. And together with Davids reply, I have a good 
clear picture of CTest. It matches what I had come up with myself, but 
it's good to know I hadn't missed some opportunity.

Thanks for you help.

Bo Thorsen.
Monty Program AB.

-- 

MariaDB: MySQL replacement
Community developed. Feature enhanced. Backward compatible.


More information about the CMake mailing list