Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to add timeout to test when using Google Testing framework

I'm in need to test C++ code - and I've decided to use Google's testing framework. I need to make sure that a test doesn't hang due to a new bug. In the .NET testing framework it's possible to add [Timeout] on to of the test in order to make sure that it does not run for too long.

How can I create a simialr behavior when using Google Test?

like image 920
Dror Helper Avatar asked Jun 05 '13 14:06

Dror Helper


People also ask

How do I turn off test Google Test?

The docs for Google Test 1.7 suggest: If you have a broken test that you cannot fix right away, you can add the DISABLED_ prefix to its name. This will exclude it from execution. This is better than commenting out the code or using #if 0 , as disabled tests are still compiled (and thus won't rot).

What is test fixture in Google Test?

If you find yourself writing two or more tests that operate on similar data, you can use a test fixture. This allows you to reuse the same configuration of objects for several different tests. To create a fixture: Derive a class from ::testing::Test .

Does Google Test run tests in parallel?

gtest-parallel is a script that executes Google Test binaries in parallel, providing good speedup for single-threaded tests (on multi-core machines) and tests that do not run at 100% CPU (on single- or multi-core machines).

How to configure timeout in TestNG?

TestNG allows users to configure a time period to wait for a test to completely execute. To specify timeout duration, use timeOut attribute of @Test annotation. The timeout value is in milliseconds. The timeout can be configured at two levels:

Why is timetestone () not working in TestNG?

As you can see from the test results, only timeTestTwo () is passed because its execution time was less than the timeout time defined in testng.xml file. The timeTestOne () execution got failed because it took more time to complete than the timeout duration configured. Let’s now go ahead and learn to set the timeout at a test method level. 3.

What is @timeout annotation in JUnit?

@Timeout Annotation JUnit 5 uses the declarative way to define the timeout behavior of a given test using the @Timeout annotation. It is unlike JUnit 4 @Test timeout attribute. A timeout configured test should fail if its execution time exceeds a given duration.

What happens if a test timeout is too long?

A timeout configured test should fail if its execution time exceeds a given duration. The execution of the test proceeds in the main thread. If the timeout is exceeded, the main thread is interrupted from another thread. The default time unit for the timeout duration is in seconds.


1 Answers

Google test does not offer something similar. http://code.google.com/p/googletest/issues/detail?id=348

You would have to add this functionality in C++

like image 173
arved Avatar answered Sep 26 '22 21:09

arved