On Mon, Jan 5, 2009 at 12:32 AM, Jeffrey Drake <span dir="ltr"><<a href="mailto:jeffd@techsociety.ca">jeffd@techsociety.ca</a>></span> wrote:<br><div class="gmail_quote"><blockquote class="gmail_quote" style="border-left: 1px solid rgb(204, 204, 204); margin: 0pt 0pt 0pt 0.8ex; padding-left: 1ex;">
<br>
I have been trying to figure out the easiest way to setup unit tests. I<br>
have seen a unit testing framework called 'check' (some documentation:<br>
<a href="http://check.sourceforge.net/doc/check.html/Setting-Up-the-Money-Build.html#Setting-Up-the-Money-Build" target="_blank">http://check.sourceforge.net/doc/check.html/Setting-Up-the-Money-Build.html#Setting-Up-the-Money-Build</a> ) but the problem seems to be that its examples are all with automake.<br>
<br>
So what is the easiest way of doing automated unit tests with CMake? I<br>
have looked at CTest, but I am not understanding it very well either. I<br>
would need a very basic example to see how it works.</blockquote><div><br>First you need to pick a unit testing framework for C++ you like. There are plenty to choose from. Once you have picked one out setting it up to work with CTest is usually fairly trivial unless you're choosing one that needs to do some autocoding in which case it's a tad more complicated.<br>
<br>How you break your tests down is up to you. Ultimately there will be a main() somewhere that calls the test assertions you want for a particular test. This main() source file along with any dependents needs to be compiled by CMake and linked just like any other binary. You may also need to link your test against libraries.<br>
<br>ADD_EXECUTABLE(FooTest FooTest.cc)<br>TARGET_LINK_LIBRARIES(FooTest bar)<br><br>To add it as a test to CTest just do:<br><br>ENABLE_TESTING() # once<br>ADD_TEST(Foo FooTest) # for all test executables<br></div></div><br>
-- <br>Philip Lowman<br>