c++ - 排除时间测试

标签 c++ visual-studio-2005 googletest

你好,我有一些类(class),例如“数学”: 头文件:

class Math
{
public:
    Math(void);
    double returnPi();
    ~Math(void);
};

和cpp文件:

#include <windows.h>
#include "Math.h"

Math::Math(void)
{   Sleep(500)  ;}

Math::~Math(void)
{   Sleep(500)  ;}

double Math::returnPi()
{   Sleep(1000) ;
    return 3.14159265;
}

我也测试了这个文件:

#include "..\gtest\gtest.h"
#include "Math.h"

TEST(Speed, Math)
{
    Math *m=new Math();
    EXPECT_LT(3.14,m->returnPi());
}

当我运行这个测试时,我看到测试通过并且这个测试的时间是 1500 毫秒,我如何从总测试时间中排除创建类所用的时间?

最佳答案

你就不能这样做吗?

#include "..\gtest\gtest.h"
#include "Math.h"

Math math;

TEST(Speed, Math)
{
    Math *m=&math;
    EXPECT_LT(3.14,m->returnPi());
}

关于c++ - 排除时间测试,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/5815693/

相关文章:

c++ - 为从特定基类派生的所有类自动生成单元测试

c++ - 是原始类型转换,在内存中创建一个新对象吗?

c++ - 涉及非平凡模板和友元声明的 C++ 语法问题

crystal-reports - VS 2005 的 CrystalReportsRedist2005_x86.msm

c++ - 不同系统上的相同构建

c++ - EXPECT_NO_THROW语句的gtest捕获结果

c++ - 将 .lib 导入另一个项目时出现问题

c++ - cpp : error when using rename function

sql - SSRS 按多个条件排序的下拉列表

c++ - 如何使用 googletest/googlemock 框架测试连续/相关的更改?