4

How to Add Timeout for a test method in C++ in Microsoft unit testing using CppUnitTestFramework ? Most of the Solutions I found online are for CSharp projects where I can add lines like [TEST_METHOD,TIME_OUT(80)] or such ,but those are not working while testing C++ (VC++) code

I have tried the below code

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

    };
}
4

1 回答 1

1

使用托管测试类。并且您可以将 Timeouts 保留在其中。

    [TestMethod(), Timeout(3000)]
    void functionName()
    {
    //
    }
于 2016-03-03T14:19:02.013 回答