Demonstration C++ Unit Test Library
- See also
- LICENSE
-
Github Repository
- Note
- This page duplicates the doxygen main page.
Introduction
JonTest is a rapid demonstration of certain techniques for the benefit of a particular person. Given that it functioned, it is presented as a modern example of the author's (rushed) work.
- Warning
- This is not intended for production work.
- Genreal coding standards conventions are violated out of necessity and convenience to the user of this tool. For example:
- Macro functions are used to facilitate reporting of filename and line number.
- The author did not create this to be used and maintained.
- Better alternatives exist, such as boost test and google test exist.
- Use them.
- Extensive real-world testing has not been performed.
This is a unit test tool providing the following:
- Minimial boilerplate for individual test suites and cases
- single definition within a .cpp file
- automatic test suite and case registration
- General assertions based around:
- boolean values
- pointer nullptr / valid (non-nullptr)
- numeric-style comparison: == != < <= > >=
- specific exception class (including base class) thrown
- assertions that are known to fail
- Expected Failures of asserts can be defined:
- Failing each contained assert will pass the test.
- If all contained asserts pass, the expected failure will then fail the test.
This is constrained by the following:
- The build system only has GNU Make definitions to build under a GNU environment using g++.
- The build system is only configured for –std=c++23
Overview
The TestRunne::get() singleton is used to run tests. Typically, this is from a main() function; however, it could be integrated into a larger testing system.
- See also
- main.cpp
Testing is organized a tree containing:
- Test Suites created with TEST_SUITE(suiteName), containing:
- (Optional) Reusable Test Case data, unique for each Test Suite that is:
- Located in the class generated by/between
TEST_SUITE(suitName) ... TEST_SUITE_END()
- (Optional) Initialized before each test case by the automatically run
setup() { ... }
- Used in each Test Case method generated by
TEST_CASE(caseName) { ... }
- (Optional) Cleaned up after each test case by the automatically run
teardown()
- (Optional) Test Case
setup(), unique for each Test Suite, run before each Test Case in the Test Suite, which may contain:
- Assertions of validatity, such as assert()
- Test Cases created with TEST_CASE(caseName), verified by/containing:
- Assertions of validatity, such as assert()
- (Optional) Test Case
teardown(), unique for each Test Suite, run before after Test Case in the Test Suite, which may contain:
- Assertions of validatity, such as assert()
Source Code Examples
assertBool_test.cpp
8 assert(
true,
"true should never fail");
#define assertTrue(first, message)
Fail this test if (first) is not true with the given message as explanation.
#define assert(first, message)
Fail this test if (first) is not true with the given message as explanation.
#define EXPECTED_FAILURE(expression, message)
Fail this test if evaluating (expression) does not result itself in a failed test.
#define assertFalse(first, message)
Fail this test if (first) is not false with the given message as explanation.
#define TEST_SUITE_END()
Finish definition of a Test Suite started with TEST_SUITE().
#define TEST_CASE(testCaseName)
Defines a Test Case method named testCaseName within a Test Suite defined by TEST_SUITE().
#define TEST_SUITE(testSuiteName)
Defines a Test Suite named testSuiteName.
Primary header files:
- See also
- Examples
Installation
- Clone this repostiroy
- Update Make/Makefile.compile.incl as necessary
make
- (Optional) include Makefile.lib.incl
- Include headers in include/JonTest such as
#include "JonTest/Assert.h"
- Link in the statically compiled lib/libJonTest.a