SetUp and TearDown methods
Although it is might be possible to perform any necessary initialization and teardown work in before and after-methods, it may be inefficient to do so. In particular when expensive resources such as database connections or global resources have to be initialized, it is beneficial to perform such actions once per fixture rather than once per test.
For such situations, cfix provides SetUp and TearDown methods. These are analogous to JUnit's @BeforeClass and @AfterClass methods. As SetUp and TearDown run only once per fixture and should initialize global resources only, they are implemented as static methods.
Like Before and After methods, SetUp and TearDown do not need any further registration -- as soon as you add static methods named SetUp and TearDown to your fixture class, cfix will treat those appropriately. Needless to say, if you only need one of these routines, you do not need to implement the other, too.
The following code illustrates the usage of SetUp and TearDown methods:
#include <cfixcc.h> class ExampleTest : public cfixcc::TestFixture { public: static void SetUp() { CFIX_LOG( L"In SetUp()" ); } static void TearDown() { CFIX_LOG( L"In TearDown()" ); } void TestOne() { CFIX_LOG( L"In TestOne()" ); } }; CFIXCC_BEGIN_CLASS( ExampleTest ) CFIXCC_METHOD( TestOne ) CFIXCC_END_CLASS()
Again, like in Before and After methods, you are free to use assertions within SetUp and TearDown methods.