CodePlea icon
CodePlea
Random thoughts on programming

C Unit Testing Library: Minctest


Summary

Fork me on GitHub

Minctest is a very minimal unit-testing "framework" written in ANSI C. It's handy when you want some easy and simple tests for a small project. It's used in many of my projects, including TinyExpr and Genann.

There also exists a Node.js port and a Lua port (see below).

Code Sample

#include "minctest.h"

void test1() {
    lok('a' == 'a');
}

void test2() {
    lequal(5, 5);
    lfequal(5.5, 5.5);
}

int main(int argc, char *argv[])
{
    lrun("test1", test1);
    lrun("test2", test2);
    lresults();
    return lfails != 0;
}
        test1         pass: 1   fail: 0      0ms
        test2         pass: 2   fail: 0      1ms
ALL TESTS PASSED (3/3)

Features

  • ANSI C with no dependencies.
  • Contained in a single C header file.
  • Reports file and line number for failed assertions.
  • Reports run time for each test.
  • Released under the zlib license - free for nearly any use.

Links

Links (Node.js Port)

Links (Lua Port)