Skip to content

Getting Started

AceUnit is a comfortable, test-discovery-based unit test framework for C, in the tradition of xUnit frameworks like JUnit. It targets developers writing firmware, drivers, operating systems, and other C programs — including in resource-constrained environments where most other frameworks don’t fit.

Write plain C functions. Name them by convention. AceUnit finds and runs them — no annotations, no macro-heavy test-registration boilerplate.

#include "leapyear.h"
#include <assert.h>
void testLeapYears(void) {
assert(isLeapYear(0));
assert(isLeapYear(4));
assert(isLeapYear(400));
}
void testNonLeapYears(void) {
assert(!isLeapYear(1));
assert(!isLeapYear(100));
}

For each fixture (an object file with test cases), AceUnit looks for functions starting with:

  • beforeAll() — one-time setup (0–1)
  • beforeEach() — setup per test case (0–1)
  • test() — test cases (n)
  • afterEach() — teardown per test case (0–1)
  • afterAll() — one-time teardown (0–1)

See Core Concepts for the full discovery model, including custom prefixes.

Terminal window
git clone https://github.com/christianhujer/aceunit.git
cd aceunit
make && sudo make install

Full details, prerequisites, and platform notes: Installation.

Terminal window
# Build your object files and test object files
cc -I /usr/local/include -c *.c
# Run aceunit on the test object files to generate fixture source
aceunit *_test.o >testcases.c
# Build the fixtures object file
cc -I /usr/local/include -c testcases.c
# Link against a runner and run
cc *.o -laceunit-abort
./a.out
AceUnit: 2 test cases, 2 successful, 0 failed.

That’s the whole workflow. Next: Core Concepts for how discovery and runners work, or Mocking if you need to test code with side effects.