Skip to content

thetic/mu.tiny

Repository files navigation

mu::tiny

Basic builds Coverage Status Documentation


mu::tiny is a C/C++ unit testing and mocking framework suited for embedded and low-resource targets.

Adding mu::tiny to Your Project

The recommended approach uses CMake FetchContent with FIND_PACKAGE_ARGS. This first attempts find_package; if mu::tiny is not installed, CMake fetches and builds it from source automatically:

cmake_minimum_required(VERSION 3.24)
project(my_tests)

include(FetchContent)
FetchContent_Declare(
    mu.tiny
    GIT_REPOSITORY    https://github.com/thetic/mu.tiny.git
    GIT_TAG           v0.8.0
    FIND_PACKAGE_ARGS 0.8
)
FetchContent_MakeAvailable(mu.tiny)

add_executable(my_tests main.cpp widget.test.cpp)
target_link_libraries(my_tests PRIVATE mu::tiny)

include(CTest)
include(mu.tiny)
mutiny_discover_tests(my_tests)

If mu::tiny is already installed and you prefer not to use FetchContent, use find_package directly:

find_package(mu.tiny 0.8 REQUIRED)

Headers

All public headers live under include/mu/tiny/. The main headers you'll use:

Header Purpose
mu/tiny/test.hpp Test and assertion macros (TEST_GROUP, TEST, CHECK, etc.)
mu/tiny/mock.hpp Mock framework (mu::tiny::mock::mock, mu::tiny::mock::Support)
mu/tiny/test.h C interface
mu/tiny/test/CommandLineRunner.hpp mu::tiny::test::CommandLineRunner (main() runner)
mu/tiny/test/Ordered.hpp TEST_ORDERED macro

Writing main

Every test executable needs a main(). The simplest form uses mu::tiny::test::CommandLineRunner:

#include "mu/tiny/test/CommandLineRunner.hpp"

using mu::tiny::test::CommandLineRunner;

int main(int argc, char** argv)
{
    return CommandLineRunner::run_all_tests(argc, argv);
}

To add plugins (e.g. mu::tiny::test::JUnitOutputPlugin, mu::tiny::test::SetPointerPlugin, mu::tiny::mock::SupportPlugin), call CommandLineRunner::install_plugin() before run_all_tests():

#include "mu/tiny/test/CommandLineRunner.hpp"
#include "mu/tiny/test/JUnitOutputPlugin.hpp"
#include "mu/tiny/mock/SupportPlugin.hpp"

using mu::tiny::test::CommandLineRunner;

int main(int argc, char** argv)
{
    mu::tiny::test::JUnitOutputPlugin junit;
    mu::tiny::mock::SupportPlugin mock_plugin;
    CommandLineRunner::install_plugin(junit);
    CommandLineRunner::install_plugin(mock_plugin);
    return CommandLineRunner::run_all_tests(argc, argv);
}

Your First Test

See examples/tests/CheatSheet.test.cpp:

  • TEST_GROUP declares a group; the struct implicitly inherits from mu::tiny::test::Test. setup() runs before each test body; teardown() runs after.
  • TEST(group, name) defines a single test.
  • A failing assertion immediately exits the test body.

Running Tests

Run the binary directly:

./build/tests/my_tests                  # run all
./build/tests/my_tests -v               # verbose: print each test name
./build/tests/my_tests -g CheatSheet    # only group "CheatSheet"
./build/tests/my_tests -n TestName      # only tests whose name contains this

Via CTest (after mutiny_discover_tests in CMakeLists):

ctest --preset GNU
ctest --preset GNU -R CheatSheet

See docs/command-line-reference.rst for all flags.

Examples

File Demonstrates
CheatSheet.test.cpp Minimal TEST_GROUP + TEST with setup(), MUTINY_PTR_SET, and assertion macros
CircularBuffer.test.cpp Full group with setup/teardown, helper methods, and multiple assertion styles

Building mu::tiny

mu::tiny uses CMake. Clone the repository and configure:

cmake -B build
cmake --build build
cmake --install build  # optional system install

Attribution

mu::tiny is descended from CppUTest. Users looking for more robust support of older language standards, or legacy compilers and platforms should consider using CppUTest instead.

About

mu::tiny is a C/C++ unit testing and mocking framework suited for embedded and low-resource targets.

Topics

Resources

License

Contributing

Stars

Watchers

Forks

Contributors