mokky14's IT diary




Adding Unit Tests to a C Project - NetBeans IDE Tutorialのサイトに以下の記述を見つけた。

Install the CUnit Testing Framework

To follow this tutorial, you must install CUnit on your system first. You can download the CUnit framework from the C Unit Testing Framework project on sourceforge.

The CUnit files page includes links to binary downloads for Windows and Linux.

For Solaris systems, you must download the CUnit-2.1-0-src.tar.gz source from the CUnit files page and use the GNU build system to build the source and install. You can get the GNU build system components autoconf and automake for Solaris from

The CUnit documentation is included in the CUnit download, or you can view it at


 $ configure
 $ gmake
 # gmake install

でインストは出来たが、インスト先のinclude/CUnitディレクトリ配下に CUError.h しか展開されなかった。

GNU build systemは多分一通り入ってるはず。

以下手順でインスト。64bit用にするため、CFLAGに-m64を指定。インストール先は /usr/local/cunit64 配下にした。

bash-3.2$ gtar xvzf CUnit-2.1-0-src.tar.gz
bash-3.2$ cd CUnit-2.1-0
bash-3.2$ ./configure --prefix=/usr/local/cunit64 CFLAGS=-m64
bash-3.2$ gmake
bash-3.2$ su
# bash
# gmake install


Sun Studio 11でのコンパイルでも動作するか確認してみる。

bash-3.2$ /opt/SUNWspro/bin/cc -L/usr/local/cunit64/lib -lcunit -I/usr/local/cunit64/include -xtarget=generic64 -o cunit_test cunit_test.c
bash-3.2$ ./cunit_test cunit_test: 重大なエラー: open に失敗しました: ファイルもディレクトリもありません。
bash-3.2$ export LD_LIBRARY_PATH=/usr/local/cunit64/lib
bash-3.2$ ./cunit_test

     CUnit - A Unit testing framework for C - Version 2.1-0

*************** CUNIT CONSOLE - MAIN MENU ***********************
(R)un all, (S)elect suite, (L)ist suites, Show (F)ailures, (Q)uit
Enter Command : R

Running Suite : Sort
        Running test : test_001
        Running test : test_002
        Running test : test_003
        Running test : test_004
        Running test : test_005

--Run Summary: Type      Total     Ran  Passed  Failed
               suites        1       1     n/a       0
               tests         5       5       5       0
               asserts      31      31      31       0

*************** CUNIT CONSOLE - MAIN MENU ***********************
(R)un all, (S)elect suite, (L)ist suites, Show (F)ailures, (Q)uit
Enter Command : Q