![]() ![]() ![]() ![]() ![]() ![]() |
Central ClassesTo understand how Scrunitizer works, you need to know how the most important interfaces and classes interact.
TestsThe test is the fundamental concept in unit testing. A test is something that handles unit testing. Two basic subtypes of a test have to be distinguished:
Test suite group together test cases. If some test cases check functionality that is closely related,
they could be put in the same test suite. Beside the grouping functionality, it is
also important that test suites are simply containers for other tests, regardless if they
are test cases or other test suites. It is important to know that when a test is added to a test
suite, the suite owns the test. That means that the suite also deletes the test when the
suite is destroyed. Test ManagerA test manager is an entity that
Test ObserversTest observers are the third import family of classes of Scrunitizer. A test observer - as the name suggests - observes test outcomes and the progress of test session. A test observer is informed by the test manager if something substantial has happened. This covers the begin and end of a test session and a single test (test cases and test suites) as well as the occurrence of exceptions. To be able to notify an observer, the test manager must know about an observer. So observer must be registered (added) to the test manager before a test session is started.Test ExecutionTo write proper test cases, it is necessary to understand how test are executed and how this is done via the Test interface.
Test PhasesA test is spitted up in three phases:
Control FlowThe control flow is depicted below:
2: If the set-up was successful, the test is executed. Also here two possibilities, failure or success. But because setting up the test fixture was already successfully executed, the tear-down function is always invoked.
b: If the test has failed, a premature test tear-down is executed. At test interface level no distinction is made between normal and premature tear-down. Only the test phase is called differently.
Test Phase IsolationIt is absolutely essential to know that the TestManager isolates each test phase completely from other test phases (of the same test and other tests). So if an exception is thrown during execution of a test phase, only this phase is stopped immediately. Other test phases are unaffected by this exception; they are executed due to the test execution schema described above.
Test Life CycleNote that executing test this way is quite similar to the life cycle of C++ objects. First, the constructor is called (set-up). If that fails (because an exception was thrown), the object is not created and the destructor is not called. If construction succeeds, the object can be used (test) and the destructor is called (tear-down) when the object is destroyed, regardless if using the object was successful or not.It is also important to remember that this execution logic applies to test cases and test suites! That means that if the set-up of a suite fails, none of its contained tests are executed. But it also means that if one or more of the contained tests fail, the suite is properly torn down anyway.
Test Construction and DestructionNote that this test execution schema has also serious impact on the usage of constructors and destructors. Because test set-up and tear-down is done in dedicated functions, constructors and destructors of test objects should not do anything that could fail! Test constructors and destructors are not called under the control of the test manager. They are normally called when the test case and test suite objects are created and destroyed. But at that point in time, the test manager does not have the control over test execution. So the exceptions are not caught and handled properly. In effect, that means that test objects have quite often empty constrictors and destructors.by Bernd Linowski [Scrunitizer] [Overview] [Cookbook] [Download] [Index] [Linosphere] Page generated: 1 Nov 2000 (C) by Bernd Linowski scrunitizer@linosphere.de |