I'm confuse about the way cppunit runs the test cases. For each test case will a new instance of the test class be runned or only one instance is created for all test cases?
About the setUp and tearDown methods, when are exactly they runned? Before/after running each testcase or once per test class?
regards
bernardo
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
Anonymous
-
2003-05-08
As per my observation... for each testcase an instance of the class will be created when you add testcase/suite to runner.
Then runner will call setUp and tearDown for each test case before and after running that test. setUp and tearDown works like constructor and destructors.... the only difference is that constructor is called when you add suite to runner and setUp is called just before invoking testcase.
Kiran.
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
By running through my TestCase with a debugger, I conclude the following.
1. A new TestCase instance is created for each function being listed through the CPPUNIT_TEST macros.
2. Before the each invocation of a listed function, TestRunner calls setUp(). After the function is completed, TestRunner calls tearDown().
setUp() and tearDown() are NOT equivalent to constructors and destructors. For example, your TestCase constructor can initialize data members, and setUp() can assign varying values to them (e.g., random values) for every invocation. This means, you test a data member that's been initialized once (in the constructor), and set a different state (configuration) to that member each time. This can help you test the robustness of your tested object to state changes during its lifetime.
The cookbook only lists very simple test cases, but a unit test can be much more sophisticated.
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
Hi,
I'm confuse about the way cppunit runs the test cases. For each test case will a new instance of the test class be runned or only one instance is created for all test cases?
About the setUp and tearDown methods, when are exactly they runned? Before/after running each testcase or once per test class?
regards
bernardo
As per my observation... for each testcase an instance of the class will be created when you add testcase/suite to runner.
Then runner will call setUp and tearDown for each test case before and after running that test. setUp and tearDown works like constructor and destructors.... the only difference is that constructor is called when you add suite to runner and setUp is called just before invoking testcase.
Kiran.
By running through my TestCase with a debugger, I conclude the following.
1. A new TestCase instance is created for each function being listed through the CPPUNIT_TEST macros.
2. Before the each invocation of a listed function, TestRunner calls setUp(). After the function is completed, TestRunner calls tearDown().
setUp() and tearDown() are NOT equivalent to constructors and destructors. For example, your TestCase constructor can initialize data members, and setUp() can assign varying values to them (e.g., random values) for every invocation. This means, you test a data member that's been initialized once (in the constructor), and set a different state (configuration) to that member each time. This can help you test the robustness of your tested object to state changes during its lifetime.
The cookbook only lists very simple test cases, but a unit test can be much more sophisticated.