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?
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).
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 .
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).
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:
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.
@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.
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.
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++
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With