duration() method from fcf::NTest::State class
Class:
Package: fcfTest
File: test.hpp
Available from version: 1.2.1
Returns or sets the total execution duration of the test suite.
The
This method supports two modes:
- Read Mode: When called without arguments, it returns a copy of the current
fcf::NTest::Duration object. - Write Mode: When called with a
fcf::NTest::Duration object as an argument, it replaces the current duration with the provided one.
Arguments
- The new duration object to be set in the state.
Result
- A copy of the current duration object.
Example: Reading the total duration
Demonstrating how to retrieve the accumulated duration of the test run.
#define FCF_TEST_IMPLEMENTATION
#include <fcfTest/test.hpp>
FCF_TEST_DEFINE ("DurationDemo", "State", "GetDuration") {
fcf::NTest::State & currentState = fcf::NTest::state ();
// 1. Retrieve the duration object
fcf::NTest::Duration currentDuration = currentState.duration ();
// 2. Output the total duration in a friendly format
fcf::NTest::log () << "Total duration: " << currentDuration.totalDurationStr (true) << std::endl;
FCF_TEST (true);
}
int main(int a_argc, char* a_argv[]) {
bool error = false;
fcf::NTest::cmdRun (a_argc, a_argv, fcf::NTest::CRM_RUN , &error);
return error ? 1 : 0;
}
Output:
Performing the test: "DurationDemo" -> "State" -> "GetDuration" ...
> Total duration: 0.000`002`756
[SUCCESS] Test completed successfully (0.000`017`838 sec)
[SUCCESS] All tests were completed.
Tests: 1 passed, 0 failed, 0 skipped, 1 total
Duration: 0.000`017`838 sec
VPSDime is an industry leading VPS hosting company that provides virtualized server services with high performance, availability and friendly support.