There are various setups: creating an app driver, creating a dummy device, doing a login.
Some test cases need only app-driver, some need app-driver and login, some need app-driver and device, others use all three.
How to make something like a Combine<Ts...> template:
#include <iostream>
// The unittest.TestCase.
struct TestCase
{
virtual void setUp() {}
virtual void tearDown() {}
};
template <typename ...Ts>
struct Combine: public TestCase, public Ts...
{
virtual void setUp() override { int t[] = { 0, (Ts::setUp(), 1)... }; }
// TODO: invert the order
virtual void tearDown() override { int t[] = { 0, (Ts::tearDown(), 1)... }; }
};
// Setups for 'login' only.
struct Login
{
void setUp() { std::cout << "Login setup" << std::endl; }
void tearDown() { std::cout << "Login teardown" << std::endl; }
};
// Setups for 'device' only.
struct Device
{
void setUp() { std::cout << "Device setup" << std::endl; }
void tearDown() { std::cout << "Device teardown" << std::endl; }
};
// A concrete test case.
struct MyTest: public Combine<Login, Device>
{
void test() { std::cout << "test" << std::endl; }
};
int main()
{
MyTest cd;
cd.setUp();
cd.test();
cd.tearDown();
Combine<Device> d;
d.setUp();
d.tearDown();
return 0;
}
Output:
Login setup
Device setup
test
Login teardown
Device teardown
Device setup
Device teardown