Re: Target setup for unit testing (using cppunit)
Re: Target setup for unit testing (using cppunit)
- Subject: Re: Target setup for unit testing (using cppunit)
- From: James Bucanek <email@hidden>
- Date: Mon, 21 Nov 2005 11:21:02 -0700
Stefan van den Oord wrote on Monday, November 21, 2005:
>Dear list members,
>
>We have a multi-platform C++ project. On the Mac, we use Xcode for
>development. Because it's multi-platform, there is no carbon or cocoa
>involved. For unit testing, we use cppunit (cppunit.sourceforge.net),
>which works ok for us.
>
>My question is about how to properly set up my targets, so that unit
>tests get automatically run after each build, but sources are compiled
>only once (compiling takes way too much time to do it more than once).
>
>I have tried several things, but I run in all kinds of trouble ranging
>from multiple compilations to unresolved symbols.
>
>Can you please advise on the right way to set this up?
I have no experience with cppunit, but I can provide some general advice based on the way that C++ unit tests in Xcode 2.1 are constructed. I'll assume that cppunit works in a similar fashion.
What you are talking about is a "dependent" unit test. The unit test bundle contains only the code for the test. The actual code to be tested is in your application binary. At build time, your source code is compiled once (for your application), and the test code is compiled separately. The tests are run by loading your application into memory using a special environment or some support code that prevents it from running normally, the test bundle is also loaded, the symbol referenced in the test bundle are linked to the actual code in your application, and the tests are run.
How your application code and test bundle get loaded into memory will depend on how cppunit works. You'll have to read up on it to find out what it expects and then construct the custom script phase of your unit test target to do whatever it is that needs to be done.
As for the undefined symbols, this bites a lot of people -- it bit me -- using C++. You have to set the "Symbols Hidden by Default" (GCC_SYMBOLS_PRIVATE_EXTERN) build setting to NO. The linker normally hides (removes) all symbols in an application which are resolved at link time. The result is that all of the functions you define in your application are hidden from the dynamic linker. You also have to include your application's binary as a "library" when building your unit tests. Otherwise, your application doesn't declare any of the functions it defines and your unit test code has nothing to link to (either at link or run time).
Of course, you'll want to have this setting turned on for the shipping version of your app.
--
James Bucanek
_______________________________________________
Do not post admin requests to the list. They will be ignored.
Xcode-users mailing list (email@hidden)
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden