简体   繁体   中英

How to setup unit tests with DejaGnu

I'm trying to learn DejaGnu ( https://www.gnu.org/software/dejagnu/ ) and would like to use it as a framework for unit tests for a C API. My build system is based on the Autotools.

In a subdirectory of ./testsuite , I have a number of C files, each of which includes dejagnu.h and uses its procedures to report passes and failures of some tests.

In ./testsuite , my Makefile.am has the line AUTOMAKE_OPTIONS=dejagnu , which causes make check to call DejaGnu's runtest .

What I am missing now is some glue code (probably some Expect files) that lets runtest find my C files with the unit tests, executes them and collects the result.

I'm looking for an explanation better than DejaGnu's description in its manual, an example setup or a link to some open source project that actually implements what I have in mind in its build system.

(I am not asking for alternative tools. This is a question especially about DejaGnu.)

Using the pass/fail functions defined in dejagnu.h is only valid for batch tools for unit testing. What you need is a simple xx.exp file like the below:

load_lib dejagnu.exp

host_execute $srcdir/unit-code/unittest

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM