DTest is a lightweight C++ testing framework for writing and executing unit tests.
- Simple and easy-to-use syntax for defining test cases.
- Color-coded output for easy identification of test results.
- Detailed test summary, including the number of tests passed, failed, and the total time consumed.
-
Copy the
dtest.hpp
anddtest.cpp
files into your project directory. -
Include
dtest.hpp
in your test files:#include "dtest.hpp"
-
Define your test cases using the provided macros:
TEST_CASE(MyTestClass) { // Your test cases go here }
-
Within each test case, use the
TEST
andEXPECTED_
macros to define your individual tests:TEST(MyTestName) { // Your test logic goes here EXPECTED_EQ(actual, expected); }
-
Compile your test files along with
dtest.cpp
and run the executable. -
View the color-coded test results and summary in the console output.
Here's a simple example of a test file using DTest:
// example_unittest.cpp
#include "DTest.hpp"
TEST_CASE(MyTestClass) {
TEST(MyTestName) {
int result = 42;
EXPECTED_EQ(result, 42);
}
}