How to set timeout in CppUnitTestFramework (C ++) in Visual Studio?

How to add a timeout for a C ++ test method in testing Microsoft modules using CppUnitTestFramework? Most of the solutions I found on the Internet are for CSharp projects where I can add lines like [TEST_METHOD, TIME_OUT (80)] or such, but they do not work during testing C ++ code (VC ++)

I tried the code below

#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
source share
1 answer

Use managed test classes. and you can save timeouts in that.

    [TestMethod(), Timeout(3000)]
    void functionName()
    {
    //
    }
+1
source

Source: https://habr.com/ru/post/1623198/


All Articles