mutest.h is a lightweight, single-header unit testing library for C, with:
- Minimal boilerplate
- Flexible assertion macros
- ANSI color output and Unicode symbols
- Optional JUnit XML export for CI
Ideal for small-to-medium C projects or embedding quick tests without external dependencies.
- ✅ Header-only: just include one file
- 🧪 Easy to write tests with
MUT_RUN_TEST(...) - 🎨 Pretty output: colors and Unicode symbols
- 🧾 Export test results in JUnit XML (
--junit) - 📋 Common assertions: equality, string, float, null, etc.
#include "mutest.h"
MUT_TEST(test_addition) {
MUT_ASSERT_EQ(2 + 2, 4);
MUT_PASS();
}
int main(int argc, char** argv) {
MUT_RUN_TEST(test_addition);
MUT_REPORT();
}gcc -o test_suite test_suite.c
./test_suite| Option | Description |
|---|---|
--junit results.xml |
Export results as JUnit XML |
MUT_ASSERT(msg, condition) // Generic assertion
MUT_ASSERT_EQ(a, b) // Integer equality
MUT_ASSERT_NEQ(a, b) // Integer inequality
MUT_ASSERT_STR_EQ(a, b) // String equality
MUT_ASSERT_TRUE(expr) // True check
MUT_ASSERT_FALSE(expr) // False check
MUT_ASSERT_NULL(ptr) // NULL pointer check
MUT_ASSERT_NOT_NULL(ptr) // Non-NULL pointer check
MUT_ASSERT_FLOAT_EQ(a, b, epsilon) // Floating-point comparisonHere's a basic workflow using --junit and GitHub test summary:
# .github/workflows/ci.yml
name: C Tests
on: [push, pull_request]
jobs:
build-and-test:
runs-on: ubuntu-latest
steps:
- name: Checkout code
uses: actions/checkout@v3
- name: Install build tools
run: sudo apt-get update && sudo apt-get install -y build-essential
- name: Build test suite
run: gcc -o test_suite test_suite.c
- name: Run tests and generate JUnit report
id: run_tests
run: |
./test_suite --junit results.xml
continue-on-error: true
- name: Upload test report
if: always()
uses: actions/upload-artifact@v4
with:
name: test-results
path: results.xml
- name: Publish test results
if: always()
uses: mikepenz/action-junit-report@v4
with:
report_paths: results.xml
- name: Fail if tests failed
if: failure() || steps.run_tests.outcome == 'failure'
run: exit 1.
├── mutest.h # The test framework
├── test_suite.c # Your test file
├── .github/workflows/ci.ymlMIT License — do whatever you want, attribution appreciated.