views:

671

answers:

1

I recently started work on a personal coding project using C++ and KDevelop. Although I started out by just hacking around, I figure it'll be better in the long run if I set up a proper unit test suite before going too much further. I've created a seperate test-runner executable as a sub project, and the tests I've added to it appear to function properly. So far, success.

However, I'd really like to get my unit tests running every time I build, not only when I explicitly run them. This will be especially true as I split up the mess I've made into convenience libraries, each of which will probably have its own test executable. Rather than run them all by hand, I'd like to get them to run as the final step in my build process. I've looked all through the options in the project menu and the automake manager, but I can't figure out how to set this up.

I imagine this could probably be done by editing the makefile by hand. Unfortunately, my makefile-fu is a bit weak, and I'm also afraid that KDevelop might overwrite any changes I make by hand the next time I change something through the IDE. Therefore, if there's an option on how to do this through KDevelop itself, I'd much prefer to go that way.

Does anybody know how I could get KDevelop to run my test executables as part of the build process? Thank you!

(I'm not 100% tied to KDevelop. If KDevelop can't do this, or else if there's an IDE that makes this much easier, I could be convinced to switch.)

A: 

Although you could manipulate the default `make` target to run your tests, it is generally not recommended, because every invocation of

make

would run all the tests. You should use the "check" target instead, which is an accepted quasi-standard among software packages. By doing that, the tests are only started when you run

make check

You can then easily configure KDevelop to run "make check" instead of just "make".

Since you are using automake (through KDevelop), you don't need to write the "check" target yourself. Instead, just edit your `Makefile.am` and set some variables:

TESTS = ...

Please have a look at the automake documentation, "Support for test suites" for further information.

vog