mirror of
https://github.com/oatpp/oatpp.git
synced 2025-04-18 19:00:23 +08:00
Merge pull request #489 from kmeinhar/master
[UnitTest]: Added before and after methods to Unit Test
This commit is contained in:
commit
e9fceb93d3
@ -36,6 +36,8 @@ void UnitTest::run(v_int32 times) {
|
||||
|
||||
v_counter objectsCount = base::Environment::getObjectsCount();
|
||||
v_counter objectsCreated = base::Environment::getObjectsCreated();
|
||||
|
||||
before();
|
||||
|
||||
v_int64 ticks = base::Environment::getMicroTickCount();
|
||||
|
||||
@ -44,6 +46,8 @@ void UnitTest::run(v_int32 times) {
|
||||
}
|
||||
|
||||
v_int64 millis = base::Environment::getMicroTickCount() - ticks;
|
||||
|
||||
after();
|
||||
|
||||
v_counter leakingObjects = base::Environment::getObjectsCount() - objectsCount;
|
||||
v_counter objectsCreatedPerTest = base::Environment::getObjectsCreated() - objectsCreated;
|
||||
|
@ -68,6 +68,14 @@ public:
|
||||
* Override this method. It should contain test logic.
|
||||
*/
|
||||
virtual void onRun() = 0;
|
||||
/**
|
||||
* Optionally override this method. It should contain logic run before all test iterations.
|
||||
*/
|
||||
virtual void before(){};
|
||||
/**
|
||||
* Optionally override this method. It should contain logic run after all test iterations.
|
||||
*/
|
||||
virtual void after(){};
|
||||
|
||||
/**
|
||||
* Run this test repeatedly for specified number of times.
|
||||
@ -82,14 +90,20 @@ public:
|
||||
|
||||
};
|
||||
|
||||
#define OATPP_RUN_TEST_0(TEST) \
|
||||
oatpp::test::UnitTest::runTest<TEST>(1)
|
||||
#define OATPP_RUN_TEST_1(TEST, N) \
|
||||
oatpp::test::UnitTest::runTest<TEST>(N)
|
||||
/**
|
||||
* Convenience macro to run test. <br>
|
||||
* Usage Example:<br>
|
||||
* `OATPP_RUN_TEST(oatpp::test::web::FullTest);`
|
||||
* Running the test 10 times:
|
||||
* `OATPP_RUN_TEST(oatpp::test::web::FullTest, 10);`
|
||||
*/
|
||||
#define OATPP_RUN_TEST(TEST) \
|
||||
oatpp::test::UnitTest::runTest<TEST>(1)
|
||||
|
||||
#define OATPP_RUN_TEST(...) \
|
||||
OATPP_MACRO_EXPAND(OATPP_MACRO_MACRO_BINARY_SELECTOR(OATPP_RUN_TEST_, (__VA_ARGS__)) (__VA_ARGS__))
|
||||
|
||||
}}
|
||||
|
||||
#endif /* oatpp_test_UnitTest_hpp */
|
||||
|
Loading…
x
Reference in New Issue
Block a user