level from class fcf::NTest::Fixture
Type:
Class:
Package: fcfTest
File: test.hpp
Available from version: 1.2.1
Defines the hierarchical scope of the fixture.
The
Available levels:
fcf::NTest::FL_PART : The fixture runs for everyPartthat matches the specified criteria.fcf::NTest::FL_GROUP : The fixture runs for everyGroupthat matches the specified criteria.fcf::NTest::FL_TEST : The fixture runs for every individualTestthat matches the specified criteria.
Example: Global vs Test Level Fixtures
Comparing the behavior of a
#define FCF_TEST_IMPLEMENTATION
#include <fcfTest/test.hpp>
// Global fixture: runs once for the whole suite
FCF_TEST_BEFORE_DEFINE ("Suite", "*", "*", fcf::NTest::FL_GLOBAL) {
fcf::NTest::log () << "--- GLOBAL START ---" << std::endl;
}
FCF_TEST_AFTER_DEFINE ("Suite", "*", "*", fcf::NTest::FL_GLOBAL) {
fcf::NTest::log () << "--- GLOBAL END ---" << std::endl;
}
// Test level fixture: runs for every single test
FCF_TEST_BEFORE_DEFINE ("Suite", "Group", "*", fcf::NTest::FL_TEST) {
fcf::NTest::log () << " [Test Setup]" << std::endl;
}
FCF_TEST_AFTER_DEFINE ("Suite", "Group", "*", fcf::NTest::FL_TEST) {
fcf::NTest::log () << " [Test Teardown]" << std::endl;
}
FCF_TEST_DEFINE ("Suite", "Group", "Test1") {
FCF_TEST (true);
}
FCF_TEST_DEFINE ("Suite", "Group", "Test2") {
FCF_TEST (true);
}
int main(int a_argc, char* a_argv[]) {
std::vector<fcf::NTest::Fixture > fixtures = fcf::NTest::storage().fixtures();
fcf::NTest::log () << "List of registered fixtures:" << std::endl;
for(fcf::NTest::Fixture & fixture : fixtures) {
std::string parts;
std::string groups;
std::string tests;
for(std::string item : fixture.parts ) { parts += std::string(parts.empty() ? "" : "|") + item; };
for(std::string item : fixture.groups ) { groups += std::string(groups.empty() ? "" : "|") + item; };
for(std::string item : fixture.tests ) { tests += std::string(tests.empty() ? "" : "|") + item; };
fcf::NTest::log () << " Fixture: " << parts << " -> " << groups << " -> " << tests
<< " (level: " << fixture.level << "; before: " << fixture.before << ")"
<< std::endl;
}
bool error = false;
fcf::NTest::cmdRun (a_argc, a_argv, fcf::NTest::CRM_RUN , &error);
return error ? 1 : 0;
}
Output:
> List of registered fixtures:
> Fixture: Suite -> * -> * (level: 0; before: 1)
> Fixture: Suite -> * -> * (level: 0; before: 0)
> Fixture: Suite -> Group -> * (level: 3; before: 1)
> Fixture: Suite -> Group -> * (level: 3; before: 0)
> --- GLOBAL START ---
> [Test Setup]
Performing the test: "Suite" -> "Group" -> "Test1" ...
[SUCCESS] Test completed successfully (0.000`000`617 sec)
> [Test Teardown]
> [Test Setup]
Performing the test: "Suite" -> "Group" -> "Test2" ...
[SUCCESS] Test completed successfully (0.000`000`265 sec)
> [Test Teardown]
> --- GLOBAL END ---
[SUCCESS] All tests were completed.
Tests: 2 passed, 0 failed, 0 skipped, 2 total
Duration: 0.000`000`882 sec
VPSDime is an industry leading VPS hosting company that provides virtualized server services with high performance, availability and friendly support.