NBCndUnit is a NetBeans plugin for C/C++ unit testing. It integrates the CppUTest, GoogleTest (gtest) / GoogleMock (gmock) and libunittest C++ unit testing frameworks.
- NetBeans 8.2
- Testing framework(s)
The Plugin is available through the Plugin Manager (Tools → Plugins → Available Plugins).
As an alternative, it’s also possible to download the NBM manually from the NetBeans Plugin Portal.
Updates are delivered as usual by the NetBeans Updater.
- Create a new NetBeans C/C++ project
- Add unit testing framework (binaries and headers) to the test settings
- Write tests
- Run them
Note: Some frameworks require verbose output.
New tests can be created either manually or using the new unit test wizard – located in the Unit Tests file category.
Example test suites are available in the examples
directory.
The tests are run as usual using the Test button.
The Test Results window shows the result of the tests.
CppUTest and libunittest C++ do not show test details per default, therefore the verbose mode must be set.
Test mains created using the new file wizard already have this mode enabled. For existing tests the examples below can be used.
At this point it's also possible to add further options (eg. test filter).
#include <CppUTest/CommandLineTestRunner.h>
#include <vector>
int main(int argc, char** argv)
{
std::vector<const char*> args(argv, argv + argc);
args.push_back("-v"); // Set verbose mode
args.push_back("-c"); // Set color output (Optional)
return RUN_ALL_TESTS(args.size(), &args[0]);
}
#include <libunittest/main.hpp>
#include <vector>
int main(int argc, char** argv)
{
std::vector<const char*> args(argv, argv + argc);
args.push_back("-v"); // Set verbose mode
return unittest::process(args.size(), const_cast<char**>(&args[0]));
}
NetBeans projects created from existing projects (eg. using custom Makefiles, CMake, …) do not have Test Support enabled by default.
To enable it, there are two Make-Targets and a configuration update required. For more information on this, please see Wiki → Using exsiting projects.
Note: This fature is currently experimental!
The project must have these Make-Targets:
Target | |
---|---|
build-tests |
builds the tests, executed before running the tests (can be empty) |
test |
executes the tests (verbose output) |
Note: CMake has make test
reserved, please see Wiki for a workaround.
In addition, the Netbeans Project configuration must contain a Test Files Folder. The project can be upgraded using the New File Wizzard for Unit Test / Test Main files:
New Files → Unit Tests → <select any>
and enable Configure custom Project
A Test Files folder is added to the NetBeans project – not visible at file level.
This step is needed only once per project, though doing this more than once has no effect.
GNU General Public License (GPL)
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.