使用 cpputest lib 无法识别 Mock().enable 和 disable 编译测试组项目
Mock().enable and disable are not recognized compiling test group project with cpputest lib
我正在尝试编译我的测试组项目,但我没有成功,因为我在输出中无法理解的下一个编译错误:
控制台输出:
"test_TestHW.c: In member function ‘virtual void TEST_TestHW_TestHW_main_Test::testBody()’:
test_TestHW.c:617:6: error: request for member ‘enable’ in ‘mock’, which is
of non-class type ‘MockSupport&(const SimpleString&, MockFailureReporter*)’
mock.enable();
^
test_TestHW.c:651:6: error: request for member ‘disable’ in ‘mock’, which is of non-class
type ‘MockSupport&(const SimpleString&, MockFailureReporter*)’
mock.disable();"
部分项目代码:
测试组代码.c文件.
/*******************************************************************************
* INCLUDES
*******************************************************************************/
#include <CppUTest/CommandLineTestRunner.h>
#include <CppUTest/TestHarness.h>
#include <CppUTestExt/MockSupport.h>
extern "C"
{
#include "RFID_Drv.h"
#include "HAL_AS393x_mock.h"
}
TEST_GROUP (TestHW)
{
protected:
public:
/* Define data accessible to test group members here */
void setup()
{
mock().disable();
}
void teardown()
{
/* Clean up steps are executed after each TEST */
mock().checkExpectations();
mock().clear();
}
};
TEST(TestHW,TestHW_main_FC_cuenta)
{
unsigned char error_val;
FLAG_Ocupado =0;
ControlEmi = 150; /* Valor de frecuencia para probar */
mock.enable();
mock().expectOneCall("CapturaTimer").andReturnValue(1000);
error_val=TestHW();
CHECK_EQUAL(error_val,FCENTRAL_CUENTA) /* Entra en el esatdo 2 */
CHECK_EQUAL(ControlEmi, 150);
mock.disable();
}
.......
//more test cases here
.......
int main(int ac, char** av)
{
/* Executes all the tests */
CommandLineTestRunner::RunAllTests(ac,av);
/* Returns value */
return(0);
}
包含在 mock.c 文件中:
/*******************************************************************************
* INCLUDES
*******************************************************************************/
#include <CppUTest/TestHarness.h>
#include <CppUTestExt/MockSupport.h>
extern "C"
{
#include "timer_mock.h"
}
unsigned long CapturaTimer(void)
{
mock().actualCall("CapturaTimer");
return mock().unsignedIntReturnValue();
}
似乎 enable/disable 没有被 cpputest 考虑和未知。我认为这可能是我错过的一件愚蠢的事情。但是现在我看不到是什么了。
我知道我正在 Cpp 测试文件中测试 C 源函数。因此,我使用的是 extern c 实例。我很惊讶,因为 dis/en 没有被识别但是 Mock().expectonecall 被识别(没有编译错误)。
- 因此,目前是否有另一种方式来 en/disable 模拟
案件?
- 能不能看出cpputest相关的包含方式有什么错误
依赖关系等?如果可能,如何修复它们?
我找到了这个错误的原因:
我忘记了“()”:
mock.enable();
必须替换为:
mock().enable();
所以它编译。
我正在尝试编译我的测试组项目,但我没有成功,因为我在输出中无法理解的下一个编译错误:
控制台输出:
"test_TestHW.c: In member function ‘virtual void TEST_TestHW_TestHW_main_Test::testBody()’:
test_TestHW.c:617:6: error: request for member ‘enable’ in ‘mock’, which is
of non-class type ‘MockSupport&(const SimpleString&, MockFailureReporter*)’
mock.enable();
^
test_TestHW.c:651:6: error: request for member ‘disable’ in ‘mock’, which is of non-class
type ‘MockSupport&(const SimpleString&, MockFailureReporter*)’
mock.disable();"
部分项目代码:
测试组代码.c文件.
/*******************************************************************************
* INCLUDES
*******************************************************************************/
#include <CppUTest/CommandLineTestRunner.h>
#include <CppUTest/TestHarness.h>
#include <CppUTestExt/MockSupport.h>
extern "C"
{
#include "RFID_Drv.h"
#include "HAL_AS393x_mock.h"
}
TEST_GROUP (TestHW)
{
protected:
public:
/* Define data accessible to test group members here */
void setup()
{
mock().disable();
}
void teardown()
{
/* Clean up steps are executed after each TEST */
mock().checkExpectations();
mock().clear();
}
};
TEST(TestHW,TestHW_main_FC_cuenta)
{
unsigned char error_val;
FLAG_Ocupado =0;
ControlEmi = 150; /* Valor de frecuencia para probar */
mock.enable();
mock().expectOneCall("CapturaTimer").andReturnValue(1000);
error_val=TestHW();
CHECK_EQUAL(error_val,FCENTRAL_CUENTA) /* Entra en el esatdo 2 */
CHECK_EQUAL(ControlEmi, 150);
mock.disable();
}
.......
//more test cases here
.......
int main(int ac, char** av)
{
/* Executes all the tests */
CommandLineTestRunner::RunAllTests(ac,av);
/* Returns value */
return(0);
}
包含在 mock.c 文件中:
/*******************************************************************************
* INCLUDES
*******************************************************************************/
#include <CppUTest/TestHarness.h>
#include <CppUTestExt/MockSupport.h>
extern "C"
{
#include "timer_mock.h"
}
unsigned long CapturaTimer(void)
{
mock().actualCall("CapturaTimer");
return mock().unsignedIntReturnValue();
}
似乎 enable/disable 没有被 cpputest 考虑和未知。我认为这可能是我错过的一件愚蠢的事情。但是现在我看不到是什么了。
我知道我正在 Cpp 测试文件中测试 C 源函数。因此,我使用的是 extern c 实例。我很惊讶,因为 dis/en 没有被识别但是 Mock().expectonecall 被识别(没有编译错误)。
- 因此,目前是否有另一种方式来 en/disable 模拟 案件?
- 能不能看出cpputest相关的包含方式有什么错误 依赖关系等?如果可能,如何修复它们?
我找到了这个错误的原因: 我忘记了“()”:
mock.enable();
必须替换为:
mock().enable();
所以它编译。