A lightweight unit testing framework for C++

Related tags

Debug unittest-cpp
Overview

Maintenance of UnitTest++, recently sporadic, is officially on hiatus until 26 November 2020. Subscribe to https://github.com/unittest-cpp/unittest-cpp/issues/180 for updates.

Build Status Build status

UnitTest++

UnitTest++ is a lightweight unit testing framework for C++. It was designed to do test-driven development on a wide variety of platforms. Simplicity, portability, speed, and small footprint are all very important aspects of UnitTest++. UnitTest++ is mostly standard C++ and makes minimal use of advanced library and language features, which means it should be easily portable to just about any platform. Out of the box, the following platforms are supported:

  • Windows
  • Linux
  • Mac OS X

Documentation

The full documentation for building and using UnitTest++ can be found on the GitHub wiki page. The contents of this wiki are also included as a git submodule under the docs folder, so version-specific Markdown documentation is always available along with the download.

Pre-requisites

While there are currently some bundled automake files, UnitTest++ is primarily built and supported using CMake.

Downloading

Latest (HEAD)

Via git:

git clone https://github.com/unittest-cpp/unittest-cpp

Via svn:

svn checkout https://github.com/unittest-cpp/unittest-cpp/trunk unittest-cpp

Latest release (v2.0.0)

Via git:

git clone https://github.com/unittest-cpp/unittest-cpp
cd unittest-cpp
git checkout v2.0.0

Via svn:

svn checkout https://github.com/unittest-cpp/unittest-cpp/tags/v2.0.0 unittest-cpp

License

UnitTest++ is free software. You may copy, distribute, and modify it under the terms of the License contained in the file LICENSE distributed with this package. This license is the same as the MIT/X Consortium license.

Contributors

GitHub Contributor Graph

Current Maintainers:

Original Authors:

Contributors not included in github history

  • Jim Tilander
  • Kim Grasman
  • Jonathan Jansson
  • Dirck Blaskey
  • Rory Driscoll
  • Dan Lind
  • Matt Kimmel -- Submitted with permission from Blue Fang Games
  • Anthony Moralez
  • Jeff Dixon
  • Randy Coulman
  • Lieven van der Heide

Historic release notes

Version 2.0.0 (2017-01-13)

  • Change Check method supporting CHECK macro to accept argument by reference
  • Introduce long macro forms (e.g. UNITTEST_CHECK); make short forms optional
  • Improved Visual Studio 2015 support
  • Full List

Version 1.6.0 (2016-02-29)

  • Add REQUIRE macro to end tests early when selected checks fail
  • Full List

Version 1.5.1 (2016-01-30)

  • pkg-config support
  • Fix for Visual Studio 2010 compilation issue in 1.5.0
  • Full List

Version 1.5 (2015-11-04)

  • Visual Studio 2015 support
  • CMake-based build management
  • Integration of SourceForge and Google Code versions of the project
  • Full List

Version 1.4 (2008-10-30)

  • CHECK macros work at arbitrary stack depth from inside TESTs.
  • Remove obsolete TEST_UTILITY macros
  • Predicated test execution (via TestRunner::RunTestsIf)
  • Better exception handling for fixture ctors/dtors.
  • VC6/7/8/9 support

Version 1.3 (2007-4-22)

  • Removed dynamic memory allocations (other than streams)
  • MinGW support
  • Consistent (native) line endings
  • Minor bug fixing

Version 1.2 (2006-10-29)

  • First pass at documentation.
  • More detailed error crash catching in fixtures.
  • Standard streams used for printing objects under check. This should allow the use of standard class types such as std::string or other custom classes with stream operators to ostream.
  • Standard streams can be optionally compiled off by defining UNITTEST_USE_CUSTOM_STREAMS in Config.h
  • Added named test suites
  • Added CHECK_ARRAY2D_CLOSE
  • Posix library name is libUnitTest++.a now
  • Floating point numbers are postfixed with 'f' in the failure reports

Version 1.1 (2006-04-18)

  • CHECK macros do not have side effects even if one of the parameters changes state
  • Removed CHECK_ARRAY_EQUAL (too similar to CHECK_ARRAY_CLOSE)
  • Added local and global time constraints
  • Removed dependencies on strstream
  • Improved Posix signal to exception translator
  • Failing tests are added to Visual Studio's error list
  • Fixed Visual Studio projects to work with spaces in directories

Version 1.0 (2006-03-15)

  • Initial release
Comments
  • downloads require running autoreconf -i and autoconf undocumented

    downloads require running autoreconf -i and autoconf undocumented

    I may have missed something but if one downloads either with git or the "release" tarballs configure is not available so one must run autoreconf -i autoconf before running configure. This seems does not seem to be documented anywhere.

    Couldn't you provide tarballs with the configure already there?

    bug documentation 
    opened by BarrySmith 20
  • Feature msvc clang

    Feature msvc clang

    UnitTest++ supports clang as a compiler for Visual Studio via native extension

    For information on enabling & using the extension see: https://blogs.msdn.microsoft.com/vcblog/2015/12/04/clang-with-microsoft-codegen-in-vs-2015-update-1/ (Since that post, an update offers v140_clang_c2) And, for instruction for CMake see: https://github.com/boostorg/hana/wiki/Setting-up-Clang-on-Windows

    However, the CMakeLists.txt for UnitTest++ uses the MSVC variable to test for the compiler type, which will be incorrect when clang is used.

    This PR uses a test against the compiler name instead. It has been verified with:

    • cmake 3.7.0 (Windows)
    • clang 3.8.0 (v140_clang_c2 Visual Studio 2015)
    • msvc 19.0.24215.1 (Visual Studio 2015)
    • cmake 3.5.2 (Ubuntu)
    • GCC 6.2.0 (Ubuntu)
    • clang 3.8.1 (Ubuntu)
    • cmake 3.4.3 (Apple)
    • AppleClang 8.0.0 generated for XCode
    • AppleClang 8.0.0 generated for command line make

    NOTE: It is also possible to attempt to install and use LLVM & Clang, but the compiler flags are a mess http://releases.llvm.org/download.html http://clang.llvm.org/docs/MSVCCompatibility.html

    opened by GabrielHare 13
  • please sync unittest-cpp with casablanca fork

    please sync unittest-cpp with casablanca fork

    Hi, since the Debian package is from a dead upstream, and you seems to be the new one, I would like to update the package with your fork. https://bugs.debian.org/cgi-bin/bugreport.cgi?bug=784665

    unfortunately a package I use (casablanca) did a fork with some new classes that makes the package fail to build with your code. http://casablanca.codeplex.com/SourceControl/latest#Release/tests/common/UnitTestpp/ how do you feel about merging them to your fork?

    after that I'll ask Debian to switch to your code :)

    duplicate 
    opened by LocutusOfBorg 13
  • Run tests/suites using custom selection from command line

    Run tests/suites using custom selection from command line

    Commands:

    • --test One or multiple test names to execute, can be combined with --suite
    • --suite One or multiple suite names to execute, can be combined with --test

    Special feature: You do not have to specify explicitely --test and --suite, you can mix suite names and test names and the cmd will find the way. The constraint is that it must have no arguments beginning with --. For disabling this feature, set allowImplicitArgs=false

    Usage examples: Explicit : myTests.exe --suite MySuite1 MyOtherSuite --test MySpecialTest MyOtherTest Implicit : myTests.exe MySpecialTest MyOtherTest MySuite1

    opened by killoctal 10
  • UnitTest++ now correctly supports CMake's find_package config mode

    UnitTest++ now correctly supports CMake's find_package config mode

    [CMakeLists.txt]

    • Bumped cmake minimum requirement to go to 3.14 as I'm not able to test with an older version
    • Added version to project so that is evident when looking at CMakeLists.txt
    • Removed include_directories as that command affects more than just UnitTest++ in favor of target_include_directories.
    • The target_include_directories uses the generator expressions to do the same thing for the BUILD_INTERFACE condition but only affects UnitTest++. The INSTALL_INTERFACE ensures that when UnitTest++ is installed client applications calling find_package for UnitTest++ only have to add the UnitTest++ target to the target_link_libraries and will get the correct include path for UnitTest++ added to their include paths.
    • Added DEBUG_POSTFIX to both library and unit test to distinguish them from each other as they are installed into the same directory and would otherwise overwrite one another.
    • Added Versioning using write_basic_package_version_file to the install so that a client can call find_package(UnitTest++ 2.1 REQUIRED) and it will be able to confirm the version. If the version is updated you could theoretically ahve a version 2.2, 2.3 ,etc... and the find_package mechanism will find the correct one. the SameMajorVersion option in that call indicates that 2.3 is compatible with 2.1 or in other words if find_package(UnitTest++ 2.1 REQUIRED) is called and 2.3 is installed that satisfies the condition but if only 3.0 was installed it will fail because of 'SameMajorVersion'.
    • Also added installation for the Version file.
    opened by dhuantes 9
  • Add Verbose Test Output

    Add Verbose Test Output

    It'd be pretty helpful to get more verbose test pass/fail output along with individual test timings. I'd be happy to do this myself, but it would involve refactoring the way tests are run and I'm not sure I should be so pretentious to think I know the best approach.

    My thought on this had been to adjust ExecuteTest<T> to call a new TestResults::OnTestSuccess() method so that you have the option to see pass/fail notices via an added m_showTestPassFail flag for the TestRunnerStdout runner.

    Open to other suggestions, someone else doing it, or getting a go-ahead to do it myself if that really is a reasonable approach.

    discussion 
    opened by AndyM84 9
  • Crash in TestUnitTest++.exe

    Crash in TestUnitTest++.exe

    I wanted to try the latest git version and used the cmake-gui program from cmake 3.0.2 to produce a mingw makefile for TDM-gcc-32 4.8.1 . When I first tried "mingw32-make" and "mingw32-make check" did work flawlessly. Then I noticed I had forgotten to set CMAKE_BUILD_TYPE inside the cmake gui. So I deleted everything and set it to Release (which sets -O3 -DNDEBUG when compiling), but this time make check crashed with a seg fault. I repeated that with RelWithDebInfo setting (this sets -O2 -g -DNDEBUG), and got a crash again. I then started the TestUnitTest++.exe with gdb and got a stacktrace:

    (gdb) run
    Starting program: C:\prg\lib\unittest-cpp\builds/TestUnitTest++.exe
    [New Thread 3812.0xa58]
    
    Program received signal SIGSEGV, Segmentation fault.
    0x77c160ad in strcat () from C:\WINDOWS\system32\msvcrt.dll
    (gdb) bt
    #0  0x77c160ad in strcat () from C:\WINDOWS\system32\msvcrt.dll
    #1  0x0022f340 in ?? ()
    #2  0x0046b8bd in (anonymous namespace)::TestTimeConstraintMacroComparesAgainstP
    reciseActual::RunImpl (this=<optimized out>)
        at ..\tests\TestTimeConstraintMacro.cpp:45
    #3  0x004a1606 in UnitTest::ExecuteTest<UnitTest::Test> (testObject=...,
        details=..., isMockTest=<optimized out>) at ../UnitTest++/ExecuteTest.h:33
    #4  0x004766aa in UnitTest::Test::Run (
        [email protected]=0x529540 <(anonymous namespace)::testTimeConstraintMacroComp
    aresAgainstPreciseActualInstance>) at ..\UnitTest++\Test.cpp:34
    #5  0x00475f73 in UnitTest::TestRunner::RunTest ([email protected]=0x22ff34,
        result=<optimized out>, curTest=<optimized out>,
        maxTestTimeInMs=<optimized out>) at ..\UnitTest++\TestRunner.cpp:67
    #6  0x0047646c in RunTestsIf<UnitTest::True> (suiteName=0x0,
        maxTestTimeInMs=0, predicate=..., list=..., this=0x22ff34)
        at ../UnitTest++/TestRunner.h:39
    #7  UnitTest::RunAllTests () at ..\UnitTest++\TestRunner.cpp:17
    #8  0x004f6ca0 in main () at ..\tests\Main.cpp:5
    

    So the crash happened somewhere inside the UNITTEST_TIME_CONSTRAINT macro, but when I tried to look at the source files where that call leads to, I saw no probable cause, and the next stack frame shows only ??. Could it be some miscompilation when doing an optimized build?

    bug wontfix 
    opened by wintertime 9
  • Deactivate/redirect older project site on here

    Deactivate/redirect older project site on here

    Hello,

    Having still 2 websites not redirecting to the current site just bring confusion. Those old website should at least have the main page indicating they are obsolete and people should go to github.

    And the issue trackers and source code management should be deactivated too

    opened by dolanor 9
  • Vs2015 support

    Vs2015 support

    Changes to support unittests in GSL library - addressing issue #79

    • Added checks for compilers supporting c++11.
    • Defined out the _NOEXCEPT for compiler versions that do not support the noexcept keyword
    • Worked around a dependency on non-portable behavior regarding the lifetimes of temporaries to ensure the line number gets added to the report of a failing test
    opened by annagrin 7
  • Introducing REQUIRE macro

    Introducing REQUIRE macro

    Introducing additional functionality to allow client code to stop a unit test when an assert fails.

    The following macro has been added:

    REQUIRE
    

    An example of when these type of checks are useful:

    TEST(SomeFixture, VerifyFooReturnsCorrectResultsGivenState)
    {
        /* some setup happened in the fixture, verify foo() returns 
           a vector of size 3 with correct values */
        std::vector<int> v = foo();
    
        REQUIRE(CHECK_EQUAL(3, v.size())); // test stops here on a fail
                                           // so we don't segfault looking at
                                           // v[0] below.
        CHECK_EQUAL(1, v[0]);
        CHECK_EQUAL(2, v[1]);
        CHECK_EQUAL(3, v[2]);
    }
    

    Multiple checks are supported as follows:

    REQUIRE({
        CHECK_EQUAL(1, 2);
        CHECK(true);
    });
    
    REQUIRE(
        CHECK_EQUAL(1,2);
        CHECK(true);
    );
    

    In the multiple check scenario, all the checks in the REQUIRE block will be run. After which, if any failures were reported, the TEST case will be stopped.

    When UNITTEST_NO_EXCEPTIONS is defined, REQUIRE is a noop.

    opened by ohz10 7
  • Add custom message to check macros

    Add custom message to check macros

    In some cases it is very helpful to be able to use a custom failure message when using UnitTest++ check macros. There are several usecases for this. One is when the default formatting of expected and actual is not optimal and the user wants to apply their own formatting to make failures easier to understand. Another example when looping over lots of test stimuli and expected results. In this case it is very beneficial to be able to print the iteration or test index to identify exactly what test instance failed rather than guessing base on line number and the values involved.

    The chosen implementation is to add DESCRIBED versions of all CHECK macros (e.g CHECK_DESCRIBED. The described versions take one additional argument, the description. The description argument will be streamed to a UnitTest::MemoryOutStream object and which is then used as the failure description. This allows the user to use the standard io manipulators to customize the formatting (e.g CHECK_DESCRIBED(b, "b is not " << std::boolalpha << true << ", b is " << b);).

    opened by elfstrom 6
  • tests/TestTestRunner.cpp: avoid referencing yet unitialized member

    tests/TestTestRunner.cpp: avoid referencing yet unitialized member

    On recent gcc-12 snapshot build fails as:

    [ 52%] Building CXX object CMakeFiles/TestUnitTest++.dir/tests/TestTestRunner.cpp.o
    unittest-cpp/tests/TestTestRunner.cpp:
      In constructor '{anonymous}::FixtureBase::FixtureBase()':
    unittest-cpp/tests/TestTestRunner.cpp:48:19:
      error: member '{anonymous}::FixtureBase::reporter' is used uninitialized [-Werror=uninitialized]
       48 |          : runner(reporter)
          |                   ^~~~~~~~
    cc1plus: all warnings being treated as errors
    

    On https://gcc.gnu.org/PR103375 Andrew suggested to match order of class members to avoid picking a member reference to yet unconstructed object.

    opened by trofi 0
  • Some minor modification

    Some minor modification

    My compiler report, that ~MemoryOutStream() {} in MemoryOutStream.h should be virtual.

    In Checks.h and others: size_t should be in std namespace. Otherwise my compiler report errors when UNITTEST_USE_CUSTOM_STREAMS is defined.

    RequiredCheckTestReporter.cpp: The file should end with a linebreak.

    RetoFelix

    opened by CanastraRF 0
  • added power support arch ppc64le on yml file.

    added power support arch ppc64le on yml file.

    Hi Team, Added power support for the travis.yml file with ppc64le. This is part of the Ubuntu distribution for ppc64le. This helps us simplify testing later when distributions are re-building and re-releasing. For more info tag @gerrith3. continuous integration build has passed without any issues after adding power arch ppc64le.kindly check and close this component.

    opened by srinivas32 0
  • Official project hiatus until 26 November, 2020

    Official project hiatus until 26 November, 2020

    I have updated the README to announce this hiatus. Those who follow this project know that maintenance has been rare and sporadic for a while now. As of today I am officially announcing a hiatus, as opposed to just letting things continue to linger.

    On or about 1 October I will announce my plans for the project going forward. I do not know what those are yet.

    Subscribe to this issue for updates.

    discussion announcement 
    opened by pjohnmeyer 13
  • Building UnitTest++ in Ubuntu for Windows: tests fail

    Building UnitTest++ in Ubuntu for Windows: tests fail

    I am installing UnitTest++ as a third party library as part of the installation process for Amanzi/ATS.

    The build process of UnitTest++ fails. The error log (attached below) indicates several tests have failed. At the moment I can only install Amanzi/ATS if I exclude the tests for UnitTest++ from the build process. Then everything seems to work fine. The developers of Amazi/ATS asked me to report this issue.

    I use Ubuntu for Windows on Windows 10 and Cmake version 3.16.3.

    unittest-build-err.log

    opened by RunaIris 0
  • Optionally disabling signal handling

    Optionally disabling signal handling

    Is there any way how not to handle signals on Linux? It looks that Unittest++ always try to suppress many signals, that appear during running the test. It is not always what we want, especially for SIGSEGV.

    I have one teoretical problem - that if some data in the memory are corrupted, next test will be running as undefined behavior.

    My practical problem is deadlock. This was caused by crash in test. My test started with a lock a mutex to singleton, after that it crashed (access to null pointer). After that framework tried to fix the signal. Skipped all the destructor (including ~lock_guard) and next test tried to lock the same mutex again.

    enhancement 
    opened by lofcek 1
Releases(v2.0.0)
Owner
UnitTest++
UnitTest++
CppUTest unit testing and mocking framework for C/C++

CppUTest CppUTest unit testing and mocking framework for C/C++ More information on the project page Slack channel: Join if link not expired Getting St

CppUTest 1.1k Nov 26, 2022
Minimal unit testing framework for C

MinUnit Minunit is a minimal unit testing framework for C/C++ self-contained in a single header file. It provides a way to define and configure test s

David Siñuela Pastor 451 Nov 18, 2022
🧪 single header unit testing framework for C and C++

?? utest.h A simple one header solution to unit testing for C/C++. Usage Just #include "utest.h" in your code! The current supported platforms are Lin

Neil Henning 544 Dec 1, 2022
UT: C++20 μ(micro)/Unit Testing Framework

"If you liked it then you "should have put a"_test on it", Beyonce rule [Boost::ext].UT / μt | Motivation | Quick Start | Overview | Tutorial | Exampl

boost::ext 929 Nov 26, 2022
Simple Unit Testing for C

Unity Test Copyright (c) 2007 - 2021 Unity Project by Mike Karlesky, Mark VanderVoord, and Greg Williams Welcome to the Unity Test Project, one of the

Throw The Switch 2.8k Nov 24, 2022
A modern, C++-native, header-only, test framework for unit-tests, TDD and BDD - using C++11, C++14, C++17 and later (or C++03 on the Catch1.x branch)

Catch2 v3 is being developed! You are on the devel branch, where the next major version, v3, of Catch2 is being developed. As it is a significant rewo

Catch Org 15.9k Nov 25, 2022
A modern, C++-native, header-only, test framework for unit-tests, TDD and BDD - using C++11, C++14, C++17 and later (or C++03 on the Catch1.x branch)

Catch2 v3 is being developed! You are on the devel branch, where the next major version, v3, of Catch2 is being developed. As it is a significant rewo

Catch Org 15.9k Nov 24, 2022
The fastest feature-rich C++11/14/17/20 single-header testing framework

master branch Windows All dev branch Windows All doctest is a new C++ testing framework but is by far the fastest both in compile times (by orders of

Viktor Kirilov 4.4k Nov 23, 2022
A testing micro framework for creating function test doubles

Fake Function Framework (fff) A Fake Function Framework for C Hello Fake World! Capturing Arguments Return Values Resetting a Fake Call History Defaul

Mike Long 540 Dec 1, 2022
Googletest - Google Testing and Mocking Framework

GoogleTest OSS Builds Status Announcements Release 1.10.x Release 1.10.x is now available. Coming Soon Post 1.10.x googletest will follow Abseil Live

Google 28.5k Nov 25, 2022
C++ Benchmark Authoring Library/Framework

Celero C++ Benchmarking Library Copyright 2017-2019 John Farrier Apache 2.0 License Community Support A Special Thanks to the following corporations f

John Farrier 723 Nov 24, 2022
A C++ micro-benchmarking framework

Nonius What is nonius? Nonius is an open-source framework for benchmarking small snippets of C++ code. It is very heavily inspired by Criterion, a sim

Nonius 338 Nov 28, 2022
test framework

Photesthesis This is a small, experimental parameterized-testing tool. It is intended to be used in concert with another unit-testing framework (eg. C

Graydon Hoare 11 Jun 2, 2021
A simple framework for compile-time benchmarks

Metabench A simple framework for compile-time microbenchmarks Overview Metabench is a single, self-contained CMake module making it easy to create com

Louis Dionne 162 Oct 23, 2022
The C Unit Testing Library on GitHub is a library designed for easy unit testing in C

The C Unit Testing Library on GitHub is a library designed for easy unit testing in C. It was written by Brennan Hurst for the purpose of providing a J-Unit-like testing framework within C for personal projects.

null 1 Oct 11, 2021
A lightweight unit testing framework for C++

Maintenance of UnitTest++, recently sporadic, is officially on hiatus until 26 November 2020. Subscribe to https://github.com/unittest-cpp/unittest-cp

UnitTest++ 509 Nov 24, 2022
A unit testing framework for C

Check Table of Contents About Installing Linking Packaging About Check is a unit testing framework for C. It features a simple interface for defining

null 923 Nov 27, 2022
CppUTest unit testing and mocking framework for C/C++

CppUTest CppUTest unit testing and mocking framework for C/C++ More information on the project page Slack channel: Join if link not expired Getting St

CppUTest 1.1k Nov 26, 2022
Minimal unit testing framework for C

MinUnit Minunit is a minimal unit testing framework for C/C++ self-contained in a single header file. It provides a way to define and configure test s

David Siñuela Pastor 451 Nov 18, 2022
🧪 single header unit testing framework for C and C++

?? utest.h A simple one header solution to unit testing for C/C++. Usage Just #include "utest.h" in your code! The current supported platforms are Lin

Neil Henning 544 Dec 1, 2022