Skip to content

mp81ss/mpunit

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

7 Commits
 
 
 
 
 
 
 
 

Repository files navigation

ARCHIVED - Moved to gitlab

MpUnit C++ unit-test framework

Introduction

An easy but featured testing free framework for C++, contained in one header only!
It is inspired to CppUnit, since basically test classes are subclasses of MpuTest
and override the Run() method, suites are subclasses of MpuSuite

You have setup()/teardown() virtual methods for both tests and suites.
Suites are a set of tests that share the same environment.

Inside tests you can put your assertions.

Features

  • Just one header: No complex setup/installation
  • Highly Portable: Tested on windows, linux, freebsd, C++98/11/14/17,20,... (see compatibility section)
  • Very easy to use (see examples)
  • Handle tests and suites (that are a set of tests)
  • Suites can set setup()/teardown() methods before/after each test execution (test level)
  • Suites can set SuiteSetup()/SuiteTeardown() before/after each suite execution (suite level)
  • Suppport stdout/file output
  • Support 4 different output formats (see output formats section)
  • Handle system exceptions (can be disabled)
  • Full support for unicode on windows (linux handle it automatically)

Output Formats

  1. stdout (The default format)
  2. HTML (A single .html page with pie chart, legend and detailed tests report)
  3. JUNIT (The classic xml format used by test frameworks)
  4. NULL (To be completely quiet)

Command Line

MpUnit supports some options at run-time, that can be set in code and overridden in cli.
You can run your test executable with -h to have a list of available options:

  • -h Show the help message
  • -f <format> Where format can be one of: stdout, html, junit, null
  • -o <filename> Write the output on filename
  • -x Disable the system exception handling (Define MPU_NO_SEH to disable at compile-time)
  • -e Stops execution at the first failed test

Except the -h switch, all others can be set to the MpUnit object:

MpUnit mpunit;
mpunit.outputFormat = MPU_OUTPUT_HTML; // MPU_OUTPUT_STDOUT is default, see enum MpuOutputType
mpunit.outputFile = "out.txt";
mpunit.enableSystemExceptions = false; // default is true
mpunit.stopOnError = true; // default is false
// addsuites/tests...
mpunit.run(argc, argv); // pass argv/argc (optional) to make mpunit handle cli

Compatibility

MpUnit has been tested with several compilers, from recent to very old ones:

  • g++ (mingw, cygwin, linux)
  • clang (windows, freebsd)
  • Visual Studio
  • Digitalmars (unicode do not works)
  • Borland 5.5.1 (Define MPU_NO_SEH, unicode do not works). Newer versions should be better

Notes

  • All available assertions begin with MPU_ASSERT...
    There is also MPU_INFO to dump a custom message, and a non-fatal assertion MPU_WARNING
  • Tests/suites are executed in the order they are added. You can use the Shuffle() method on both
    MpUnit and MpuSuite-derived objects to randomize tests execution order
  • You can query status with method GetStatus
  • You can reset the MpUnit object by calling method Reset()