【发布时间】:2016-01-07 05:23:07
【问题描述】:
如何使用 CppUnitTestFramework 在 Microsoft 单元测试中为 C++ 中的测试方法添加超时?我在网上找到的大多数解决方案都是针对 CSharp 项目的,我可以在其中添加诸如 [TEST_METHOD,TIME_OUT(80)] 之类的行,但是在测试 C++ (VC++) 代码时这些行不起作用
我试过下面的代码
#include "stdafx.h"
#include "CppUnitTest.h"
#include "../src/factorial_dp.cpp"
#include "stdio.h"
using namespace Microsoft::VisualStudio::CppUnitTestFramework;
namespace spec
{
TEST_CLASS(factorial_dpSpec)
{
public:
//Add Timout for these methods
TEST_METHOD(Smallnumber)
{
int result = fact(5);
Assert::AreEqual(120, result, L"5 fact should be 120", LINE_INFO());
}
};
}
【问题讨论】:
-
我在 Google 上搜索了您的标题(以及最相关的三个词)并找到了 (codereview.stackexchange.com/questions/84697/…)。也许应该做的伎俩。
-
我读过,这一行是正在测试的时间。 std::this_thread::sleep_for(std::chrono::milliseconds{ 1 });有没有办法用任何给定的函数或无限循环替换该行,在这种情况下它不起作用
标签: c++ testing time microsoft-cpp-unit-test