john01dav
john01dav

Reputation: 1962

How can I do C++ Unit Tests in Netbeans?

I attempted to follow the tutorial here to get Netbeans unit testing setup for C++. It talks about a "Select Elements" portion of the test setup wizard in which one selects the parts of the actual project that are available to the test. This stage in the wizard is absent with the wizard starting on "Name and Location":

Wizard Screenshot

When I create a unit test without this part of the wizard, I am unable to include any headers from my project unless I include it in the format #include "../Header.h" and, when I do that, g++ has problems linking the included header to the corresponding implementation.

What am I doing incorrectly and what do I need to do to have my unit tests work correctly?

NOTE: I am trying to use cppunit, but, the dialog is missing "Select Elements" for all 4 available testing formats (simple C, CUnit, simple C++, CPPUnit).

Upvotes: 0

Views: 1797

Answers (1)

Captain Giraffe
Captain Giraffe

Reputation: 14705

The "Select elements" part of the wizard comes up when you activate the wizard by right-clicking the .cpp-file or the .h-file and click "Create Test".

If you do "New .. / C/C++ tests/.." this part of the wizard isn't there.

I am unable to include any headers from my project unless I include it in the format #include "../Header.h"

There seems to be an oversight by the template/wizard writers to not address the fact that your tests lies in a directory tests. You can fix this by adding your project folder as an -I include directory switch. Use an absolute path.

Linking should not be a problem since the compiler targets the Build directory. If you do have problems with linking check the properties of the linker options in your CPPUnit test project folder.

Upvotes: 1

Related Questions