You are here

Writing testcases

Primary tabs

Ideally, any non-trivial GNUnet code should be covered by automated testcases. Testcases should reside in the same place as the code that is being tested. The name of source files implementing tests should begin with "test_" followed by the name of the file that contains the code that is being tested.

Testcases in GNUnet should be integrated with the autotools build system. This way, developers and anyone building binary packages will be able to run all testcases simply by running make check. The final testcases shipped with the distribution should output at most some brief progress information and not display debug messages by default. The success or failure of a testcase must be indicated by returning zero (success) or non-zero (failure) from the main method of the testcase. The integration with the autotools is relatively straightforward and only requires modifications to the Makefile.am in the directory containing the testcase. For a testcase testing the code in foo.c the Makefile.am would contain the following lines:

check_PROGRAMS = test_foo
TESTS = $(check_PROGRAMS)
test_foo_SOURCES = test_foo.c
test_foo_LDADD = $(top_builddir)/src/util/libgnunetutil.la

Naturally, other libraries used by the testcase may be specified in the LDADD directive as necessary.

Often testcases depend on additional input files, such as a configuration file. These support files have to be listed using the EXTRA_DIST directive in order to ensure that they are included in the distribution. Example:

EXTRA_DIST = test_foo_data.conf

Executing make check will run all testcases in the current directory and all subdirectories. Testcases can be compiled individually by running make test_foo and then invoked directly using ./test_foo. Note that due to the use of plugins in GNUnet, it is typically necessary to run make install before running any testcases. Thus the canonical command make check install has to be changed to make install check for GNUnet.