Author Topic: Doing unit tests (cppunit)  (Read 18436 times)

Offline kfmfe04

  • Multiple posting newcomer
  • *
  • Posts: 27
Re: Doing unit tests (cppunit)
« Reply #15 on: July 06, 2009, 04:17:47 pm »
Unfortunately, the "ugliness" is a byproduct of the fact that cxxtest generates .cpp files from .hpp files and then expects you to compile and link them.  Luckily, this results in a very lightweight and easy-to-use system.

I'm not sure what is happening on your system configuration, but dependencies between projects seem to work okay for me - ie if I edit my real library code and target my test-driver application, C::B knows to compile the library before linking.

What I'd really like to see is a JUnit or NUnit like system with a GUI, but none seems to be available C++ - it's convenient to be able to run a sub-set of all the tests through a GUI when I am concentrating on something specific.

Anyhow, best not to waste too much time thinking about this - as long as the framework does its job, better to just get some framework up, and concentrate on the coding itself...


Offline Jenna

  • Administrator
  • Lives here!
  • *****
  • Posts: 7255
Re: Doing unit tests (cppunit)
« Reply #16 on: July 06, 2009, 05:25:25 pm »
Everything works fine, except that if I modify the real project the test won't recompile and rerun.
There are two options that I have:
1. Convert the test project to target in the real project (will try it tonight)
2. Somehow make C::B to recompile the test project every time I build the real project. I've tried the project dependencies dialog, but it does not work :( The thing I need is to setup the post-build step of the real project to build my test project, but I suppose that is not possible at the moment (and never will be).

What about using the C::B-project as dependency for the test-project and recompile the test-project ?

Offline oBFusCATed

  • Developer
  • Lives here!
  • *****
  • Posts: 13413
    • Travis build status
Re: Doing unit tests (cppunit)
« Reply #17 on: July 06, 2009, 08:36:20 pm »
Dependencies don't work at all, no matter if test_app depends on the plugin or the vice-versa.
Could it be because I don't link the test_app to the plugin?
(most of the time I ignore long posts)
[strangers don't send me private messages, I'll ignore them; post a topic in the forum, but first read the rules!]

Offline kfmfe04

  • Multiple posting newcomer
  • *
  • Posts: 27
Re: Doing unit tests (cppunit)
« Reply #18 on: July 07, 2009, 08:16:06 am »
From my limited experience with cxxtest and C::B (about 2 weeks), I was able to get dependencies working correctly, but it was time-consuming figuring out how to set-up a test framework to work well within C::B.  When I say correctly, I mean if I edit any of my main code, a minimal-but-necessary number of compiles/links occur in my system.

As far as I can tell, C::B dependencies work fine, but settings in 3 or 4 or 5 different places can definitely have an impact on whether dependencies work the way you expect.

If you describe >very specifically<, what you mean by "Dependencies don't work at all", maybe some of us can help. 

What is your setup for your code and testing framework?  In the same project?  In different projects?  Are you using any pre-build or post-build steps for your testing framework?  Is the test failing to compile or link or both?

Dependencies don't work at all, no matter if test_app depends on the plugin or the vice-versa.
Could it be because I don't link the test_app to the plugin?


Offline oBFusCATed

  • Developer
  • Lives here!
  • *****
  • Posts: 13413
    • Travis build status
Re: Doing unit tests (cppunit)
« Reply #19 on: July 07, 2009, 11:38:30 am »
I've explained my setup in my first post (not very clear though, excuse me for that :( )

Here it is simplified:

1. my real project - in the current case a C::B plugin
2. my test project - do not like with the real project, because I don't export anything useful for testing. Instead I have added the files I want to test from the real project in the test project.

I've put the two projects in a workspace, then I've tried to make the test project depend on the real project (and vice versa) through "project -> properties -> project dependencies". I've not set any external dependencies, because the two output files don't depend on each other.
(most of the time I ignore long posts)
[strangers don't send me private messages, I'll ignore them; post a topic in the forum, but first read the rules!]

Offline kfmfe04

  • Multiple posting newcomer
  • *
  • Posts: 27
Re: Doing unit tests (cppunit)
« Reply #20 on: July 07, 2009, 12:16:33 pm »
That's better.  I've never done plug-in development, but I assume that your test project should link with the plug-in library (is it a .a or .dll or .so)?  Correct me if I'm wrong.

1. Is it a compile failure, a link failure, or a dependency failure which is preventing some automatic compile or link?
2. Specifically, what did you try that causes you to think a dependency failed (compile or link)?
3. Has the dependency succeeded under any condition?  In other words, is it failing under a certain condition or does it always fail?

My setup is very similar to yours, but I have found that I DO NOT need to add any files from my real project to my test project - only the directory for the real project headers under the test project's build directory to search for.

I've explained my setup in my first post (not very clear though, excuse me for that :( )

Here it is simplified:

1. my real project - in the current case a C::B plugin
2. my test project - do not like with the real project, because I don't export anything useful for testing. Instead I have added the files I want to test from the real project in the test project.

I've put the two projects in a workspace, then I've tried to make the test project depend on the real project (and vice versa) through "project -> properties -> project dependencies". I've not set any external dependencies, because the two output files don't depend on each other.
« Last Edit: July 07, 2009, 12:21:05 pm by kfmfe04 »

Offline oBFusCATed

  • Developer
  • Lives here!
  • *****
  • Posts: 13413
    • Travis build status
Re: Doing unit tests (cppunit)
« Reply #21 on: July 27, 2009, 09:15:33 pm »
I've found my problem ... the two projects need to have the same Targets, otherwise the dependencies doesn't work.
In my case my plugin project has only the default target, but my test project have the Debug/Release combo.
I've renamed default to be Debug and now it works....
(most of the time I ignore long posts)
[strangers don't send me private messages, I'll ignore them; post a topic in the forum, but first read the rules!]