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.

  1. is there way avoid calling setup , teardown after each set of parameter test?
  2. 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

Popular posts from this blog

commonjs - How to write a typescript definition file for a node module that exports a function? -

openid - Okta: Failed to get authorization code through API call -

thorough guide for profiling racket code -