https://github.com/maxtek6/maxtest
Lightweight unit testing framework for C++ and CMake
https://github.com/maxtek6/maxtest
Last synced: 11 months ago
JSON representation
Lightweight unit testing framework for C++ and CMake
- Host: GitHub
- URL: https://github.com/maxtek6/maxtest
- Owner: maxtek6
- License: mit
- Created: 2024-12-19T12:22:28.000Z (over 1 year ago)
- Default Branch: master
- Last Pushed: 2025-06-02T04:26:43.000Z (about 1 year ago)
- Last Synced: 2025-06-02T14:08:00.486Z (about 1 year ago)
- Language: C++
- Size: 4.88 KB
- Stars: 1
- Watchers: 0
- Forks: 0
- Open Issues: 1
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# Maxtest
Simple unit testing framework for C/C++ and CMake. This project was
created due to the significant overlap in the unit testing code for
our existing C and C++ projects.
This is not meant to be a replacement for GTest or any other widely
used testing framework. It lacks support for benchmarking, mocking,
and other features that would be useful for a complex project. This
framework is most useful for developers who want to bootstrap simple
unit tests to establish test coverage in their projects.
## Requirements
+ C++11
+ CMake >= 3.10
## Basic Usage
A basic unit test file should be written as follows:
```c++
#include
// any additional classes or functions here
MAXTEST_MAIN
{
MAXTEST_TEST_CASE(test_name)
{
const int n(5);
MAXTEST_ASSERT(n > 0);
};
}
```
There are 3 macros defined by the `maxtest.hpp` header:
+ `MAXTEST_ASSERT(COND)`: assert the result of a boolean expression. If
the evaluated expression is `false`, the test will fail.
+ `MAXTEST_TEST_CASE(NAME)`: defines a single test case to be run. By
default, a test case will always pass unless one of the assertions
invoked by `MAXTEST_ASSERT` fails.
+ `MAXTEST_MAIN`: indicates the start of the block where the test cases
will be defined. All test cases must be declared in this block. No other
classes or functions can be declared in this block.
+ Note that any calls to the functions in the `maxtest` namespace may be
legal, but they are not recommended and their behavior is undefined.
## Integration with CMake
Maxtest can be integrated as a git submodule or imported via `FetchContent`:
```cmake
FetchContent_Declare(
Maxtest
GIT_REPOSITORY https://github.com/maxtek6/maxtest.git
GIT_TAG master
)
FetchContent_MakeAvailable(Maxtest)
```
Once the package has been imported, an executable can be created using the
targets. Assume the file `main.cpp` has the example code from above:
```cmake
maxtest_add_executable(unittest main.cpp)
```
Using the `maxtest_add_test` command, declare each test name as declared in
the source file using `MAXTEST_TEST_CASE`:
```cmake
# "" represents any additional args passed when the test is run
maxtest_add_test(unittest test_name)
maxtest_add_test(unittest test_name_with_args arg1 arg2)
```
## Roadmap
+ Test coverage using `gcovr`
+ Improved CMake functions