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

partOrder() method from fcf::NTest::Storage class

int partOrder(const char* a_name) const
void partOrder(const char* a_name, int a_order)

Class: fcf::NTest::Storage

Package: fcfTest

File: test.hpp

Available from version: 1.2.1

Sets or gets the execution priority of a specific test part.

The partOrder method allows you to control the execution order of test parts. In , tests are organized into a hierarchy: Part > Group > Test.

This method has two distinct behaviors depending on whether it is used for reading or writing:

  • Write Mode: When called with an int argument, it assigns a priority value to the specified part. Lower values are executed first.
  • Read Mode: When called with a single const char* argument, it returns the assigned priority. If the part has not been assigned a specific order, it returns the default constant FCF_TEST_ORDER_DEFAULT.

Arguments

const char* a_name
- The name of the test part.

int a_order
- The priority order to assign to the part (lower values run first).
Result
int
- The assigned priority order for the part, or the default order if not set.

Example: Controlling Part Execution Order

Demonstrating how to set a custom execution order for different parts to ensure critical tests run first.

#define FCF_TEST_IMPLEMENTATION #include <fcfTest/test.hpp> #include <iostream> FCF_TEST_DEFINE("Critical", "Core", "FastTest") { fcf::NTest::log() << "Running critical test..." << std::endl; FCF_TEST(true); } FCF_TEST_DEFINE("General", "Core", "SlowTest") { fcf::NTest::log() << "Running general test..." << std::endl; FCF_TEST(true); } int main(int a_argc, char* a_argv[]) { bool error = false; fcf::NTest::Storage& storage = fcf::NTest::storage(); // 1. Set execution order: 'Critical' part runs before 'General' part storage.partOrder("Critical", 1); storage.partOrder("General", 10); // 2. Verify the order (Read Mode) int criticalOrder = storage.partOrder("Critical"); fcf::NTest::log() << "Critical part order: " << criticalOrder << std::endl; // 3. Run the tests fcf::NTest::cmdRun(a_argc, a_argv, fcf::NTest::CRM_RUN, &error); return error ? 1 : 0; }

Output:

> Critical part order: 1 Performing the test: "Critical" -> "Core" -> "FastTest" ... > Running critical test... [SUCCESS] Test completed successfully (0.000`004`390 sec) Performing the test: "General" -> "Core" -> "SlowTest" ... > Running general test... [SUCCESS] Test completed successfully (0.000`002`709 sec) [SUCCESS] All tests were completed. Tests: 2 passed, 0 failed, 0 skipped, 2 total Duration: 0.000`007`099 sec