MinUnit

なんかC++使えるって理由だけでC言語での開発させられそう・・・
しかも、年上の新人と組まされる可能性が*1


というのは置いといて。C言語で使えるユニットテストツールを探したところ、すばらしいものが。

/* file: minunit.h */
#define mu_assert(message, test) do { if (!(test)) return message; } while (0)
#define mu_run_test(test) do { char *message = test(); tests_run++; \
                                if (message) return message; } while (0)
extern int tests_run;
JTN002 - MinUnit -- a minimal unit testing framework for C

実質3行ですよ3行。
使い方は

#include <stdio.h>
#include "minunit.h"

int tests_run = 0;

int foo = 7;
int bar = 4;

static char * test_foo() {
    mu_assert("error, foo != 7", foo == 7);
    return 0;
}

static char * test_bar() {
    mu_assert("error, bar != 5", bar == 5);
    return 0;
}

static char * all_tests() {
    mu_run_test(test_foo);
    mu_run_test(test_bar);
    return 0;
}

int main(int argc, char **argv) {
    char *result = all_tests();
    if (result != 0) {
        printf("%s\n", result);
    }
    else {
        printf("ALL TESTS PASSED\n");
    }
    printf("Tests run: %d\n", tests_run);

    return result != 0;
}
JTN002 - MinUnit -- a minimal unit testing framework for C

素晴らしい・・・
しかもやってることは超シンプルなんで、「○○Unit?信じられるかそんなもん!」な人でも説得しやすい。
それでいて必要な機能は備えているという。

*1:しかも言語経験皆無。新人研修でVB.NETC#をやった程度・・・「か」ってなんですか「か」って