Menu

CPPUnit execution flow

Help
2003-05-07
2003-05-16
  • Bernardo Sana

    Bernardo Sana - 2003-05-07

    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

     
    • Anonymous

      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.

       
    • Ofri Sadowsky

      Ofri Sadowsky - 2003-05-16

      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.

       

Log in to post a comment.

Want the latest updates on software, tech news, and AI?
Get latest updates about software, tech news, and AI from SourceForge directly in your inbox once a month.