小编Sam*_*all的帖子

Unity 框架单元测试未定义对“setUp”和“tearDown”的引用

我从Unity for C 单元测试库中复制了最简单的代码,并设置了一个非常基本的测试,我从站点复制并粘贴了该代码:

#include "unity/src/unity.h"

int main(void)
{
    UNITY_BEGIN();
    int a = 1;
    TEST_ASSERT( a == 1 ); //this one will pass
    TEST_ASSERT( a == 2 ); //this one will fail
    return UNITY_END();
}
Run Code Online (Sandbox Code Playgroud)

我在终端中输入的内容:

gcc TestDumbExample.c ./unity/src/unity.c -o Test
Run Code Online (Sandbox Code Playgroud)

我在终端中收到此错误消息:

/tmp/ccqgFGn8.o: In function `UnityDefaultTestRun':
unity.c:(.text+0x26af): undefined reference to `setUp'
unity.c:(.text+0x26ca): undefined reference to `tearDown' collect2:
error: ld returned 1 exit status

Unsure why this error is occurring and it has undefined references.
Run Code Online (Sandbox Code Playgroud)

c gcc unit-testing compiler-errors unity-test-framework

4
推荐指数
1
解决办法
1817
查看次数