mirror of
https://github.com/oatpp/oatpp.git
synced 2025-01-18 16:43:57 +08:00
[UnitTest]: Added before and after methods to Unit Test
There might be some setup/teardown code that is no supposed to run in every iteration of a test. Additionally this code is not included in the time measurement.
This commit is contained in:
parent
d9e8e0cb34
commit
f4a178f9f7
@ -37,6 +37,8 @@ void UnitTest::run(v_int32 times) {
|
|||||||
v_counter objectsCount = base::Environment::getObjectsCount();
|
v_counter objectsCount = base::Environment::getObjectsCount();
|
||||||
v_counter objectsCreated = base::Environment::getObjectsCreated();
|
v_counter objectsCreated = base::Environment::getObjectsCreated();
|
||||||
|
|
||||||
|
before();
|
||||||
|
|
||||||
v_int64 ticks = base::Environment::getMicroTickCount();
|
v_int64 ticks = base::Environment::getMicroTickCount();
|
||||||
|
|
||||||
for(v_int32 i = 0; i < times; i++){
|
for(v_int32 i = 0; i < times; i++){
|
||||||
@ -45,6 +47,8 @@ void UnitTest::run(v_int32 times) {
|
|||||||
|
|
||||||
v_int64 millis = base::Environment::getMicroTickCount() - ticks;
|
v_int64 millis = base::Environment::getMicroTickCount() - ticks;
|
||||||
|
|
||||||
|
after();
|
||||||
|
|
||||||
v_counter leakingObjects = base::Environment::getObjectsCount() - objectsCount;
|
v_counter leakingObjects = base::Environment::getObjectsCount() - objectsCount;
|
||||||
v_counter objectsCreatedPerTest = base::Environment::getObjectsCreated() - objectsCreated;
|
v_counter objectsCreatedPerTest = base::Environment::getObjectsCreated() - objectsCreated;
|
||||||
|
|
||||||
|
@ -68,6 +68,14 @@ public:
|
|||||||
* Override this method. It should contain test logic.
|
* Override this method. It should contain test logic.
|
||||||
*/
|
*/
|
||||||
virtual void onRun() = 0;
|
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.
|
* Run this test repeatedly for specified number of times.
|
||||||
@ -87,8 +95,12 @@ public:
|
|||||||
* Usage Example:<br>
|
* Usage Example:<br>
|
||||||
* `OATPP_RUN_TEST(oatpp::test::web::FullTest);`
|
* `OATPP_RUN_TEST(oatpp::test::web::FullTest);`
|
||||||
*/
|
*/
|
||||||
#define OATPP_RUN_TEST(TEST) \
|
#define OATPP_RUN_TEST_0(TEST) \
|
||||||
oatpp::test::UnitTest::runTest<TEST>(1)
|
oatpp::test::UnitTest::runTest<TEST>(1)
|
||||||
|
#define OATPP_RUN_TEST_1(TEST, N) \
|
||||||
|
oatpp::test::UnitTest::runTest<TEST>(N)
|
||||||
|
#define OATPP_RUN_TEST(...) \
|
||||||
|
OATPP_MACRO_EXPAND(OATPP_MACRO_MACRO_BINARY_SELECTOR(OATPP_RUN_TEST_, (__VA_ARGS__)) (__VA_ARGS__))
|
||||||
|
|
||||||
}}
|
}}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user