我正在尝试对使用GLib编写的一些C代码运行简单的单元测试。我正在尝试做类似的事情:
#include <math.h>
#include <stdio.h>
#include <glib.h>
static void
test_stuff ()
{
g_assert (1 == 1); //Say
}
int main (int argc, char **argv)
{
g_test_init (&argc, &argv);
g_test_add_func ("/TestTest", test_stuff);
return g_test_run();
}
但是当我编译(比如一个名为exec的二进制文件)并尝试使用gtester运行它(甚至直接运行所述二进制文件)时,我收到以下错误:
me@laptop:tests$ gtester exec
TEST: exec... (pid=6503)
(process:6503): GLib-CRITICAL **: g_test_init: assertion `vararg1 == NULL' failed
FAIL: exec
Terminated
我是否缺少某些东西,也许我应该在运行测试时传递变量?
答案 0 :(得分:10)
你错过了g_test_init()
函数的参数。 The docs将原型显示为:
void g_test_init(int *argc,
char ***argv,
...);
和
...:保留以供将来扩展。目前,您必须传递NULL。
因此,您需要传递NULL
作为第三个参数。