Cでのユニットテスト
Posted on Mon, 15 Dec 2008 10:07:27 +0900
仕事ではC言語をよく使っていますが、ユニットテストが 手動とかめんどくさすぎます。自分でAPIを作成してますが、 チェック用の関数がint用とか文字列用とか分かれてしまってかっこ悪い。
なにかいい手はないかと探してみると、C言語用のユニットテスト用フレームワークも 色々あることがわかった。その中でも MinUnit はシンプルでどこでも使い回しがききそう。 わずか3行です。
短いので引用。
/* 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;
なるほど、比較式をそのまま渡してやればいいのか。