Using the CUTE Eclipse Plug-in

The CUTE Eclipse plug-in integrates the CUTE C++ unit testing framework into the Eclipse CDT C/C++ integrated development environment. This plug-in provides all the important features that Java developers know from the JUnit plug-in:

  • Wizards to initialize and set up new tests
  • Test navigator with green/red bar
  • Diff-viewer for failing tests
  • Rerun functionality for single test (e.g. a failed one)

This page shows how to use the CUTE Eclipse plug-in once it is installed.

Functionality

Create a Project

Select File > New > C++ Project. In the C++ Project dialog, the CUTE Eclipse plug-in provides two new C++ project wizards in addition to those that come with CDT by default:

Select the type of CUTE project you want:

  • CUTE Project creates a standalone test project.
  • CUTE Suite Project asks you for a name, and creates a test suite with that name.

Specify the Project name and click Next >. On the following wizard page, you can choose which CUTE headers to use (recommended are the newest ones) and if you want to use Gcov and/or CUTE's boost-headers (if one of these optional CUTE features was installed). If you specify an existing Eclipse project you want to test, CUTE creates a unit test for that project. Upon clicking Finish, the wizard creates a project containing all the CUTE unit test framework's source files.

If you did not install Boost in the standard location or use CUTE's boost-headers, you will need to specify boost's headers installation location.

All of the wizards create a trivial test in file src/Test.cpp that will get you started. Expand this Test.cpp to create your unit test.

Test Navigator with Green/Red Bar

To build the project, select the menu Project > Build All. Then, right click on the HelloCute project and select Run As > CUTE Test.

Modify Test.cpp as shown below to make your unit test succeed.

#include "cute.h" 
#include "ide_listener.h" 
#include "xml_listener.h" 
#include "cute_runner.h" 

void thisIsATest() {
    std::string first, second, expected;
    first = "Hello";
    second = "World";
    expected = "Hello World";
    ASSERT_EQUAL(expected, first + " " + second);
}

bool runAllTests(int argc, char const *argv[]) {
    cute::suite s { };
    //TODO add your test here
    s.push_back(CUTE(thisIsATest));
    cute::xml_file_opener xmlfile(argc, argv);
    cute::xml_listener<cute::ide_listener<>> lis(xmlfile.out);
    auto runner = cute::makeRunner(lis, argc, argv);
    bool success = runner(s, "AllTests");
    return success;
}

int main(int argc, char const *argv[]) {
    return runAllTests(argc, argv) ? EXIT_SUCCESS : EXIT_FAILURE;
}

Diff-Viewer for Failing Tests

With Test.cpp modified as follows...

#include "cute.h" 
#include "ide_listener.h" 
#include "xml_listener.h" 
#include "cute_runner.h" 

void thisIsATest() {
    std::string first, second, expected;
    first = "Hello";
    second = "World";
    expected = "Hello World";
    ASSERT_EQUAL(expected, first + "    \t  \n" + second);
}

bool runAllTests(int argc, char const *argv[]) {
    cute::suite s { };
    //TODO add your test here
    s.push_back(CUTE(thisIsATest));
    cute::xml_file_opener xmlfile(argc, argv);
    cute::xml_listener<cute::ide_listener<>> lis(xmlfile.out);
    auto runner = cute::makeRunner(lis, argc, argv);
    bool success = runner(s, "AllTests");
    return success;
}

int main(int argc, char const *argv[]) {
    return runAllTests(argc, argv) ? EXIT_SUCCESS : EXIT_FAILURE;
}

...double clicking at the location of the blue arrow (as shown above) pops up the result comparison.

Spaces, tabs and newlines can be turned on.

Assertion Functions

The following assertion macros are available in the CUTE testing framework.

ASSERTM(msg, cond)
ASSERT(cond)
ASSERT_EQUALM(msg, expected, actual)
ASSERT_EQUAL(expected, actual)
ASSERT_EQUAL_DELTAM(msg, expected, actual, delta)
ASSERT_EQUAL_DELTA(expected, actual, delta)
ASSERT_EQUAL_RANGES(expbeg, expend, actbeg, actend)
ASSERT_EQUAL_RANGESM(msg, expbeg, expend, actbeg, actend)
ASSERT_GREATERM(msg, left, right)
ASSERT_GREATER(left, right)
ASSERT_GREATER_EQUALM(msg, left, right)
ASSERT_GREATER_EQUAL(left, right)
ASSERT_LESSM(msg, left, right)
ASSERT_LESS(left, right)
ASSERT_LESS_EQUAL(left, right)
ASSERT_LESS_EQUALM(msg, left, right)
ASSERT_THROWS(code, exc)
ASSERT_THROWSM(msg, code, exc)
FAIL()
FAILM(msg)
ASSERT*_DDT(cond, failure)
ASSERT*_DDTM(msg, cond, failure)
ASSERT_NOT_EQUAL_TO(left, right)
ASSERT_NOT_EQUAL_TOM(msg, left, right)

See Writing and Running CUTE Unit Test Suites for details.

Rerun Individual Tests, Suites or Groups of Tests

From within the CUTE Tests view you can select tests or suites from the tree and let these run individually. If the view was populated from a "Debug as CUTE Test" the re-run will be within the debugger as well.

XML Output

The CUTE framework can generate XML output. While this doesn't directly link with the CUTE framework, you can click on the generated XML file in the project's root folder from within CDT and might get Eclipse's JUnit View if you have installed JDT as well. The XML output might be interesting for you when using hudson or jenkins.