FCF 2.0 development in progress...
> > > > > >
[News] [C++ Libraries API] [C++ Downloads] [Donate to the project] [Contacts]

duration() method from fcf::NTest::State class

fcf::NTest::Duration duration() const
void duration(fcf::NTest::Duration a_duration)

Class: fcf::NTest::State

Package: fcfTest

File: test.hpp

Available from version: 1.2.1

Returns or sets the total execution duration of the test suite.

The duration method provides access to the fcf::NTest::Duration object that tracks the total time elapsed during the test execution process.

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

fcf::NTest::Duration a_duration
- The new duration object to be set in the state.
Result
fcf::NTest::Duration
- 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