views:

1365

answers:

3

I'm starting a new project and my company has standardized development on NetBeans. I need to do unit testing, though, and can't find a unit testing plugin for C++. As I said, it's a new project, so I'm open to trying any C++ unit testing framework.

EDIT: I've decided on CppUnit, since I'm very familiar with JUnit and the learning curve will be flat. I'd still be interested in any tricks for compiling and running tests from NetBeans IDE so I (and more importantly, my co-workers) don't have to open a shell to run the tests.

EDIT 2: Some more details are coming out of the answers and comments I've gotten so far. It would be nice to have a red-bar, green-bar GUI plugin for C++, but I've pretty much given up on that. I know how to change the compiler and add flags in NetBeans, but it seems that what I really need are instructions on adding a custom make target that will build and run my tests.

A: 

This is a recurring question. You should have a look at the responses already given.

Luc Hermitte
My question is specific to NetBeans.
Bill the Lizard
As long as netbeans is able to understand the usual error messages generated by compilers like the ones from the *cc family, it changes nothing. Just add a rule in your makefile -- that is compatible with the TU framework you will eventually choose.
Luc Hermitte
+1  A: 

Again, the same question you left unanswered: Isn't netbeans able to jump to the error message you obtain when you compile your projects ?

If no, you should solve this problem first.

If yes, then, where is the problem ? Just call your UT framework from your makefile.

Luc Hermitte
"Just call your TU framework from your makefile." First of all, I don't know how to do that. Your answer might be helpful if you explained this a little. Second, you've mentioned "TU framework" twice. Are we talking about the same thing here?
Bill the Lizard
Test Unit Frameworks -> CppUnit (if you don't mind to repeat yourself), boost.test, CxxTest, google-something-tests, Fructose, ... There are many TU frameworks. AFAIK, you just need to edit your makefile to add the rule that build the Tests, and execute them....
Luc Hermitte
...that's what I do with CxxTest as the error messages it produces are compatibles with C *nix compilers. All I have left to do in to clic on the TU assertion failure from my development environment....
Luc Hermitte
... It seems to me that the real issue is that you don't know how Netbeans compiles your projects. Am I right ?
Luc Hermitte
[BTW, what is the correct English formulation (I'm not a native speaker): "Test Unit Framework", or "Unit Testing Framework" ?]
Luc Hermitte
Sorry about the language mix up. Here we call it Unit Test framework, or UT framework. I should have recognized from context that you meant the right thing, I just wanted to be sure.
Bill the Lizard
As for your other question, I do know that NetBeans uses a makefile to compile my code. I know how to change the compiler (I'm cross compiling for an ARM processor) and add the necessary flags, but not much else.
Bill the Lizard
Do you (or someone else) maintain the makefile, or does NetBeans do it for you ?
Luc Hermitte
NetBeans is doing it for me. I make changes to the build through the IDE. I haven't edited many makefiles by hand since college.
Bill the Lizard
Thanks for your help so far on this. I'm going to ask my makefile issue as a separate question.
Bill the Lizard
+1  A: 

First, you'll need to create one or more separate executables that actually run your unit tests. Since that's code to be built it should be integrated into your build system -- whether it's make or cmake or bjam or whatever.

Second, you'll want to actually run your tests. You can probably add a target to your build system that runs the resulting test executables which, on failure, should produce output error messages that conform to conventional build error message output (with filename and line numbers).

Then, it's simply a matter of informing NetBeans (or Eclipse, or CodeBlocks) of your new build target (e.g., make test). The output scanner should detect any error messages and allow you to quickly jump the file/line with the test failure.

That's basically what Luc Hermitte was talking about. If you actually want red-bar/green-bar GUI functionality then, yeah, you'll need to find a special plugin for that.

Pat Notz