Coder Social home page Coder Social logo

offa / nbcndunit Goto Github PK

View Code? Open in Web Editor NEW
13.0 3.0 4.0 694 KB

NetBeans C/C++ unit testing plugin – supporting CppUTest, GoogleTest (gtest) / GoogleMock (gmock) and libunittest C++.

License: GNU General Public License v3.0

C++ 1.20% Java 98.36% HTML 0.40% Shell 0.03%
netbeans netbeans-plugin unit-testing c cpp googletest cpputest java

nbcndunit's Introduction

CI GitHub release License NetBeans Java

NBCndUnit is a NetBeans plugin for C/C++ unit testing. It integrates the CppUTest, GoogleTest (gtest) / GoogleMock (gmock) and libunittest C++ unit testing frameworks.

Requirements

Compatibility Note:

NetBeans releases newer than 8.x don't support C / C++ yet.

Supported C/C++ unit testing frameworks

Installation

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.

Update

Updates are delivered as usual by the NetBeans Updater.

Getting started

  1. Create a new NetBeans C/C++ project
  2. Add unit testing framework (binaries and headers) to the test settings
  3. Write tests
  4. Run them

Note: Some frameworks require verbose output.

Creating new Tests

New tests can be created either manually or using the new unit test wizard – located in the Unit Tests file category.

Examples

Example test suites are available in the examples directory.

Running tests

The tests are run as usual using the Test button.

The Test Results window shows the result of the tests.

Enabling verbose mode

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).

CppUTest

#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]);
}

libunittest C++

#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]));
}

Using existing Projects

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!

Project requirements

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.

Enable Test Support

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.

License

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/>.

nbcndunit's People

Contributors

offa avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar

nbcndunit's Issues

add support for NetBeans projects with existing source code

This plugin doesn't currently work with NetBeans projects that are created from existing source code.

Steps to reproduce:

  1. Create a new NetBeans C++ project selecting "C/C++ Project with Existing Sources".
  2. Select a directory containing a C++ source tree with unit tests.
  3. Existing unit tests aren't recognized as such and can't be run in the IDE because the "Test" button is grayed out.

It would be great if the plugin could be taught how to work with unit tests in these kinds of NetBeans projects through manual configuration of project settings.

Drop the CppUTest TeamCity support?

Is the CppUTest TeamCity support (#17) really needed and go into the next release? Or should it be dropped from the mainline?

It adds extra maintenance effort but does not bring much benefit (correct?).

Test Results window showing incorrect results

I have a strange issue with a project i have just migrated from CppUnit to google test.
I have 160 unit tests but the test results window is saying 311 which is wrong, and showing the same test cases twice.
The output from google test is correct although I dont know enough about it to know what in the stdout may be causing the issue (I'm not streaming or printing anything myself to stdout).
Using Google test 1.7.0 in Netbeans 8.1 on Mac OS X 10.9.5
When I create a simple hello world new project the Tests results window shows the correct results.

I have attached google test stdout and screen grab of netbeans test window

googletest-nbresultswindow
googletest-stdout.txt

Running Debug Test results in Sigtrap window

I have a number of developers with different native projects who have reported the inability to debug tests using google test or cppunit. Don't know if this is plugin related or netbeans related.

If they right click on a test and run "Test" everything runs fine, all tests run, If they right click on a test and run "Debug Test" then a sigtrap window is displayed. Screen shots are attached.

screen shot 2016-01-09 at 09 36 42

All using various iterations of Netbeans 8.1 including latest (as of time of post), on Mac OS X 10.9.5. Java Projects work fine.

screen shot 2016-01-09 at 09 28 04

Surefire v2.20 is broken

Surefire v2.20 is broken and fails at least with JUnit 5 (see #45). It's therefore downgraded to v2.19.x until the bug has been fixed.

From the JUnit 5 docs:

Due to a memory leak in Surefire 2.20, the junit-platform-surefire-provider currently only works with Surefire 2.19.1.

Findbugs broken on JDK9

Findbugs broken on JDK9:

[…]
     [java] Warning: Unknown version of Java
     [java] edu.umd.cs.findbugs.JavaVersionException: Could not parse Java version string: 9
     [java] 	at edu.umd.cs.findbugs.JavaVersion.<init>(JavaVersion.java:68)
     [java] 	at edu.umd.cs.findbugs.JavaVersion.<clinit>(JavaVersion.java:44)
     [java] 	at edu.umd.cs.findbugs.DetectorFactory.isEnabledForCurrentJRE(DetectorFactory.java:248)
[…]

Apiguardian warning

Apiguardian warning:

unknown enum constant org.apiguardian.api.API.Status.STABLE
  reason: class file for org.apiguardian.api.API$Status not found
unknown enum constant org.apiguardian.api.API.Status.STABLE
unknown enum constant org.apiguardian.api.API.Status.STABLE
unknown enum constant org.apiguardian.api.API.Status.STABLE
unknown enum constant org.apiguardian.api.API.Status.STABLE
  reason: class file for org.apiguardian.api.API$Status not found
unknown enum constant org.apiguardian.api.API.Status.STABLE
unknown enum constant org.apiguardian.api.API.Status.STABLE
unknown enum constant org.apiguardian.api.API.Status.STABLE

Test not recognized if cout << "sometext" << endl; used in TEST body

Hi,
today I updated Your plugin to the latest 0.6.0 available in plugin portal.
During porting my test from older tool to CppUTest I found that I should not use cout in TEST body or the test will not be recognized and displayed in Tests Result Window.

TEST(EGOLSCH, SetupEvent)
{
...
std::cout << "timer events = " << msgque_out.Count() << std::endl;
CHECK_TRUE(msgque_out.Count() > 30);
}
This is probably because terminal looks like
TEST(EGOLSCH, SetupEvent)timer events = 0

When changed to
std::cout << std::endl << "timer events = " << msgque_out.Count() << std::endl;
everything is Okay.

I'm not sure if this is an issue, I'm writing just for your knowledge :)

Travis CI build failures

Travis CI build failures on master and netbeans_dev_builds branches. Jobs were executed by cron (#24).

$ mvn install -DskipTests=true -Dmaven.javadoc.skip=true -B -V
Error: JAVA_HOME is not defined correctly.
  We cannot execute /usr/lib/jvm/java-7-openjdk/bin/java
[…]
Your build has been stopped.

Only JDK7 Jobs are affected, JDK8 works correct.

Calculate suite runtime

As the default output of CppUTest, the TeamCity output doesn't contain a runtime per suite. Only the duration of each test case is shown. The total time must be calculated from those.

CI cron job

Travis CI cron jobs for master and netbeans_dev_builds branches.

Go to failure for failed Gtests

Failed gtest tests should contain the line of failure (from #7) and allow a jump to it:

When there's a test failure, google test outputs the file and line number of the failure, but that information isn't picked up by the Test Results GUI in NB. It would really be great if that was included so the failure could be clicked on in the Test Results GUI and have NB jump to the file and line of the error.

Make the test report clickable

Hello,
first of all, I want to thank you for your great job!
Just a few days after I started working with CppUTest framework I found your NB plugin, easy to install, easy to use.
Only one thing is not working as expected - previously I used to make unit tests with NB simple testing feature, and every time some test failed I was able to navigate to the file and test simply by double clicking on the report (or the context menu: Go to Source).

With your plugin this is not possible, even if test failure location is specified in the report.
I'm using the latest official NB release, 8.0.2. Since I'm not Java developer I cannot help you improve this plugin, but I can offer you my services as a tester :)

Kindly regards,
Mariusz Midor

Coloured gtest output is not detected properly

Coloured gtest output is not detected properly (from #7):

I'm using google test and I noticed that it's important for the output of gtest to not be colored. If it is colored, the plugin doesn't pick up any results and it doesn't give any hint as to why. It kind of looks like the unit test crashed based on the output shown, but that's not the case. You might want to mention that somewhere in your documentation.

Add support for check/libcheck unit testing framework

This is a feature request for consideration. It maybe beneficial if this project could also support check/libcheck unit testing framework.
https://github.com/libcheck/check/
https://libcheck.github.io/check/

I use your cmake completion, and came across this sometime back. I am slowly integrating check/libcheck into my projects. Thus the interest in integration. If I can help I will, but presently already bit off way more than I can chew, so working on that...

Thank you for consideration of this feature request!

Add support for >= C++11

Add support for >= C++11 to the test templates. Those may use override and other means of new features.

This should stay optional as not everyone is using modern C++ (or even C++).

Are Unit tests executed on CI?

Are Unit tests executed on CI? The output says no:

[INFO] -------------------------------------------------------
[INFO] T E S T S
[INFO] -------------------------------------------------------
[INFO]
[INFO] Results:
[INFO]
[INFO] Tests run: 0, Failures: 0, Errors: 0, Skipped: 0

Default options not enabled in the UI

Default options not enabled in the UI. None of the checkboxes is enabled (or disabled for inactive).

  • Tested using the 'New Main' Wizard on the modern C++ (#29) branch.
  • JDK: JDK9
  • NB: Dev (running on NB8.2)

Parameterized Google Tests report wrong test result

Google Test allows for the creation of parameterized tests that will run multiple times across a collection of values provided to the test. The output of these tests are slightly different than normal Google Test output (as seen below). The NBCndUnit plugin fails to correctly parse the output causing the test to show a passing result when it actually fails. Also the test name is not parsed correctly due to the different format under parameterized testing.

Sample parameterized test output:
[----------] 3 tests from X (1 ms total)
[ RUN ] MyTestTitle/ParamX.Y/0
test.cpp:40: Failure
Value of: false
Actual: false
Expected: true
[ FAILED ] MyTestTitle/ParamX.Y/0, where GetParam() = 1 (1 ms)
.....

Sample output 2:
[ RUN ] MyTestTitle/ParamX.Y/0
test.cpp:40: Failure
Value of: false
Actual: false
Expected: true
[ FAILED ] MyTestTitle/ParamX.Y/0, where GetParam() = 16-byte object <01-00 00-00 00-7F 00-00 0A-00 00-00 00-00 00-00>
......

The existing regular expression breaks down when it hits the ", where GetParam() = " causing the output on the FAILED line not to match.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.