General questions on parameterized test in googletest -
background:i writing session table incoming traffic. table should hold active udp/tcp connections.
i using googletest package test implementation. prepare parameterised test based on fixture in following format:
class sessiontest - initialize staff. struct connectioninfo - holds set of connection parameters (ips, ports, etc..) class sessiontestprepare : sessiontest , testing::withparaminterface<connectioninfo> - initialization. test_p(sessiontestprepare, test) - holds test cases , logic. instantiate_test_case_p(default, sessiontestprepare_ testing::values( conectioninfo{}, conectioninfo{}, conectioninfo{},
)
i noticed each time new parameters tested, sessiontest constructor , setup function called (and of course destructor , teardown).
note: sessiontable declared , initialized here.
- is there way avoid calling setup , teardown after each set of parameter test?
- is there way keep state of session table after each test without make global (i.e. when testing second connection parameters, first still in table)?
to run set , tear down once in test fixture, use setuptestcase
, teardowntestcase
instead of setup
, teardown
. , shared resources can stored in fixture static member variables. example:
class sessiontestprepare : public ::testing::withparaminterface<connectioninfo> //... { public: static void setuptestcase(); static void teardowntestcase(); static connectioninfo * shared_data; //... }
setuptestcase
called before first parameter test begins , teardowntestcase
called after last parameter test ends. can create/delete shared resources in these functions.
Comments
Post a Comment