【问题标题】:Unity Framework Unit Testing undefined reference to "setUp" and "tearDown"Unity 框架单元测试未定义对“setUp”和“tearDown”的引用
【发布时间】:2019-08-20 12:39:40
【问题描述】:

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

#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();
}

我在终端输入的内容:

gcc TestDumbExample.c ./unity/src/unity.c -o Test

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

/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.

【问题讨论】:

    标签: c unit-testing gcc compiler-errors unity-test-framework


    【解决方案1】:

    需要在文件中定义setUp和tearDown,我以为是unity.c中的

    void setUp (void) {} /* Is run before every test, put unit init calls here. */
    void tearDown (void) {} /* Is run after every test, put unit clean-up calls here. */
    

    【讨论】:

      【解决方案2】:

      单元测试框架像构造函数/析构函数一样使用这些函数。由于您正在做一个简单的测试,您可以使用这些名称定义两个空函数。

      【讨论】:

        【解决方案3】:

        我遇到了类似的问题。

        解决方案:

        1. 转到您的“unity.c”文件。
        2. 搜索“void setUp(void);”

        -> 用括号“void setUp(void){}”替换分号。对拆解执行相同的操作。

        【讨论】:

          猜你喜欢
          • 1970-01-01
          • 2013-01-05
          • 2012-01-13
          • 1970-01-01
          • 1970-01-01
          • 1970-01-01
          • 1970-01-01
          • 2018-04-08
          • 1970-01-01
          相关资源
          最近更新 更多