[英]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.我正在尝试学习 DejaGnu ( https://www.gnu.org/software/dejagnu/ ) 并希望将其用作 C API 单元测试的框架。 My build system is based on the Autotools.我的构建系统基于 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.在./testsuite
的子目录中,我有许多 C 文件,每个文件都包含dejagnu.h
并使用其过程报告某些测试的通过和失败。
In ./testsuite
, my Makefile.am
has the line AUTOMAKE_OPTIONS=dejagnu
, which causes make check
to call DejaGnu's runtest
.在./testsuite
,我的Makefile.am
有一行AUTOMAKE_OPTIONS=dejagnu
,这会导致make check
调用 DejaGnu 的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.我现在缺少的是一些胶水代码(可能是一些 Expect 文件),它让runtest
通过单元测试找到我的 C 文件,执行它们并收集结果。
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.我正在寻找比 DejaGnu 在其手册中的描述更好的解释、示例设置或指向某个开源项目的链接,这些项目实际上在其构建系统中实现了我的想法。
(I am not asking for alternative tools. This is a question especially about DejaGnu.) (我不是要求替代工具。这是一个特别是关于 DejaGnu 的问题。)
Using the pass/fail functions defined in dejagnu.h is only valid for batch tools for unit testing.使用 dejagnu.h 中定义的 pass/fail 函数仅对单元测试的批处理工具有效。 What you need is a simple xx.exp file like the below:您需要的是一个简单的 xx.exp 文件,如下所示:
load_lib dejagnu.exp load_lib dejagnu.exp
host_execute $srcdir/unit-code/unittest host_execute $srcdir/unit-code/unittest
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.