DrMock is a C++17 testing and mocking framework for Windows, Linux and macOS.
- Unit test framework
- On-the-fly mock object source code generation at compile time
- State machine-like mock objects
- Qt5 integration
DRTEST_TEST(launch)
{
auto rocket = std::make_shared<drmock::samples::RocketMock>();
// Define rocket's state behavior.
rocket->mock.toggleLeftThruster().state()
// Source state // Destination state // Input value
.transition("", "leftThrusterOn", true )
.transition("leftThrusterOn", "", false)
.transition("rightThrusterOn", "allThrustersOn", true )
.transition("allThrustersOn", "rightThrusterOn", false);
rocket->mock.toggleRightThruster().state()
.transition("", "rightThrusterOn", true )
.transition("rightThrusterOn", "", false)
.transition("leftThrusterOn", "allThrustersOn", true )
.transition("allThrustersOn", "leftThrusterOn", false);
rocket->mock.launch().state()
.transition("", "failure")
.transition("*", "liftOff"); // "*" = catch-all
// Check that the pad launches the rocket with at least one thruster enabled.
drmock::samples::LaunchPad launch_pad{rocket};
launch_pad.launch();
DRTEST_ASSERT(rocket->mock.verifyState("liftOff"));
}
Note. Only the state of rocket
after the test matters. It's fine
to keep toggeling the thrusters as long as at least one is enabled at
launch. DrMock allows tests to be designed without a particular
implementation in mind.
See BUILD.md for instructions.
-
Tutorials:
-
The DrMock API is documented in the source files; the docs are doxygen-compliant, but you must specify the Doxyfile yourself
-
Cookbook, a collection of common design patterns for DrMock
See CONTRIBUTING.md.
During the configuration of DrMock's build system, we have profited greatly from the following sources:
- P. Arias: It's Time To Do CMake Right
- D. Berner: Cmake line by line - creating a header-only library.
- DrAutomaton, Qt5-based cellular automaton library