CppUnit is a unit testing framework module for the C++ programming language. It allows “CppUnit Documentation”. ^ Jenkins plug-in for CppUnit and other Unit Test tools; ^ fork presented as CppUnit v; ^ fork. This document gives a simple example of CppUnit. The content covers the download of CppUnit,an example of CppUnit, compilation and. Easy refactoring of code. The unit test is a form of documentation in cppunit. C++ framework. Derived from jUnit. Centered around unit testing as a concept -.

Author: Mazumuro Kajijas
Country: Nicaragua
Language: English (Spanish)
Genre: Marketing
Published (Last): 12 February 2006
Pages: 339
PDF File Size: 10.3 Mb
ePub File Size: 7.90 Mb
ISBN: 816-6-38705-555-2
Downloads: 44659
Price: Free* [*Free Regsitration Required]
Uploader: Fenrizuru

TestCase TestCase has a virtual method void runTest we must override. The only change we need to make in the Makefile is the linking of the files. We also have a TestResult class which is the controller or event manager and a TestResultCollector class that listens for tests being run. The value a is the real part and b is the complex part. It is a collection of tests run together as a unit.

The test function names begin with “test”. We’ll call it TestCartesianComplexMath. If they all pass, you get an OK message.


All of this goes in int main. TestFixture Make the commonly used variables private. We need some new flags at the top of the file. It runs all the test suites and collects the results. Declare them public along with the test functions.

Some of the most common are: Adding these functions to the test case can be a little errorprone, but cppunjt CppUnit has helper macros. Since we used the helper macro for test suite registration, test. Our TestCase will have several instances of CartesianComplex that will be needed by all tests in the test case.

TestFixture is a subclass of TestCase test cases. Cppuint one of them fails, it’ll tell you the name of the test case, the name of the source file and the line number. We define the rest in the.

Each test a function handles a small part of the test, and combined the functions test the whole thing. C will automatically call all linked and registered TestCase classes.

There are different types of asserts we can use in our test functions. These flags will be used to tell the compiler where to find the CppUnit headers and declarations. Cppunir test class will extend CppUnit’s TestCase class.


Our class will handle the basic math operations addition, subtraction, multiplication and division. We will be using the latest stable version, release 1. The private variables should be created and destroyed in the respective TestFixture function. The function runTest is handled cocumentation the macros.

There are several parts of unit testing.

CppUnit – Wikipedia

Our tests are called from inside the runTest method. First we create a suite to run the tests. TestResult controller; TestResultCollector result; controller. More can be found at the Wikipedia entry or about.

CppUnit Documentation

Notice that the registration name matched the class name. We’ll see the importance of this name registration later.

Unit tests are code, separate and independent from the code it tests, that can be run automatically. CppUnit has a special class, called a fixture, for just this purpose.