c++ - unity C unittest 框架可以用来对 C++ 代码进行单元测试吗?
问题描述
我正在使用统一框架在 AtMega32A 上对我的 C 代码进行单元测试。这很好用。现在我想知道我是否可以以某种方式欺骗统一来测试我的 C++ 代码。
我制作了一个小的概念证明程序,它通过一个公共函数公开了 C++ 类的所有成员。现在我想在该公共函数中放置一些断言宏。该程序可以在这里找到: https ://github.com/cdwijs/cpp_unit_test
在我的主要我有以下几点:
int main(void)
{
UNITY_BEGIN();
//RUN_TEST(myPrivate.executeTest); //unity_internals.h(707,65): error: invalid use of non-static member function
//RUN_TEST((void*)myPrivate.executeTest); //error: invalid use of member function (did you forget the '()' ?)
//RUN_TEST((func)))myPrivate.executeTest); //error: 'func' was not declared in this scope
//RUN_TEST(&myPrivate.executeTest); //error: cannot convert 'void (Private::*)()' to 'UnityTestFunction {aka void (*)()}' for argument '1' to 'void UnityDefaultTestRun(UnityTestFunction, const char*, int)'
UNITY_END();
myPrivate.more();
myPrivate.more();
myPrivate.less();
/* Replace with your application code */
while (1)
{
}
}
在 Private_test.cpp 我有以下内容:
#include "private.h"
#include "unity.h"
void Private::executeTest (void)
{
myNumber = 3;
TEST_ASSERT_EQUAL_INT(3,myNumber);
more();
TEST_ASSERT_EQUAL_INT(4,myNumber);
}
我不知道如何运行测试功能。有任何想法吗?我是在寻找正确的方向,还是应该使用专门针对 C++ 的测试框架?
解决方案
推荐阅读
- java - Micronaut cli graphql 设置
- c# - 如何获取字符串内部数据类型的大小?
- fortran - 为什么当我更改结果变量的名称时,使用 f2py 编译的 Fortran 函数返回零?
- dictionary - 使用静态映射的类无法编译
- angular - URLSearchParams 不是构造函数
- javascript - 在 VUE 中拖放文件
- scala - Scala 类型检查抱怨 lambda,而不是显式 Function
- javascript - Why does the youtube ytplayer object not update when navigating between youtube videos?
- typescript - 打字稿找不到自定义类型定义文件
- git - 为什么git是法语的?