void
appendParam(
const std::string& a_partName,
const std::string& a_groupName,
const std::string& a_testName,
fcf::NTest::SharedPtrAny... a_parameterPack)
void
appendParam(
const fcf::NTest::Test& a_a_test,
fcf::NTest::SharedPtrAny... a_parameterPack)
void
appendParam(
const fcf::NTest::TestPath& a_testPath,
fcf::NTest::SharedPtrAny... a_parameterPack)
Class: fcf::NTest::Storage
Package: fcfTest
File:
test.hpp
(
link_to_the_declaration_in_the_file
,
link_to_the_implementation_in_the_file
)
Available from version: 1.2.4
Adds a parameters to a specific test case.
The appendParam method is used to register a new parameters for a specific test. This is a fundamental method for implementing parameterized testing, where you want to run the same test logic with different data sets.
You can provide the parameter as a fcf::NTest::SharedPtrAny object, allowing you to store any type of data within the framework.
Arguments
const std::string& a_partName
- The name of the test part.
const std::string& a_groupName
- The name of the test group.
const std::string& a_testName
- The name of the test function.
fcf::NTest::SharedPtrAny... a_parameterPack
- The parameter objects to be added.
Example: Adding parameters manually
Demonstrating how to use appendParam with SharedPtrAny to add different types of data.
#define FCF_TEST_IMPLEMENTATION
#include <fcfTest/test.hpp>
FCF_TEST_BEFORE_DEFINE("*", "*", "*", fcf::NTest::FL_GLOBAL) {
// Use appendParam to add test parameters as a SharedPtrAny to the test
fcf::NTest::storage().appendParam("Manual", "Params", "AppendTest",
fcf::NTest::SharedPtrAny::make<int>(42),
fcf::NTest::SharedPtrAny::make<int>(53),
fcf::NTest::SharedPtrAny::make<int>(71));
}
FCF_TEST_DEFINE("Manual", "Params", "AppendTest") {
fcf::NTest::SharedPtrAny p = fcf::NTest::state().param();
FCF_TEST(p.is<int>(), "Parameter should be an int");
int* val = p.cast<int>();
fcf::NTest::log() << "Value: " << *val << std::endl;
}
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: "Manual" -> "Params" -> "AppendTest" ...
== Parameter set: 1
> Value: 42
== Parameter set: 2
> Value: 53
== Parameter set: 3
> Value: 71
[SUCCESS] Test completed successfully (0.000`019`086 sec)
[SUCCESS] All tests were completed.
Tests: 1 passed, 0 failed, 0 skipped, 1 total
Duration: 0.000`019`086 sec