template class TestAppliance<class T> : TestCase

A template that creates test cases by applying functor objects to an arbitrary object.

This template generates test cases that use applicables for all phases of a unit test: Test set-up, execution and tear-down. So a TestAppliance is an extension of a TestGadget. And also here, the fixture object itself does not need to inherit from TestCase.
Most likely, all the needed applicables are created from member functions of the test fixture class. They are all owned by the test appliance. So when the appliance is destroyed, this objects are deleted as well.

The apply template function could be used to construct Applicable-instances out of member functions of the fly. Note that there also versions of the apply functions that allow to specify constant parameters for the member functions.
The test appliance itself could be easily created with the following template functions:

template<class T> inline TestAppliance<T>* makeTestAppliance (
      const string& name,
      Applicable<T>* testFunc, 
      Applicable<T>* setUpFunc,
      Applicable<T>* tearDownFunc
);

template<class T> inline TestAppliance<T>* makeTestAppliance (
      const string& name,
      T* object,
      Applicable<T>* testFunc, 
      Applicable<T>* setUpFunc,
      Applicable<T>* tearDownFunc,
      bool releaseFixture = false
);

template<class T> inline TestAppliance<T>* makeStdTestAppliance (
      const string& name,
      Applicable<T>* testFunc
);

template<class T> inline TestAppliance<T>* makeStdTestAppliance (
      const string& name,
      T* object,
      Applicable<T>* testFunc, 
      bool releaseFixture = false
);
 
The makeStdTestAppliance functions automatically use the member function setUp () and tearDown () to construct set-up and tear-down applicables, so the fixture class T must have such member functions. If the fixture object is given as parameter, it is assumed that the instance is shared between test appliances, so releaseFixture defaults to false.



Public Members:
    TestAppliance ( const string name, T* fixture, Applicable<T>* testFunc, Applicable<T>* setUpFunc, Applicable<T>* tearDownFunc, bool releaseFixture ) ;
    Create a new test appliance instance.
    The test, set-up and tear-down function applicables must be specified. If releaseFixture is true, the fixture instance is owned by the appliance, so it is deleted when the test appliance is destroyed.

    virtual ~TestAppliance () ;
    Destroys the test appliance
    Deletes the fixture object and all used applicables.

    virtual void setUp () ;
    Construction of the test environment.
    Calls the set-up applicable.

    virtual void test () ;
    Execute the test.
    Calls the test action applicable.

    virtual void tearDown () ;
    Deconstruction of the test environment.
    Calls the tear-down applicable.




The Scrunitizer C++ Unit Test Framework
by Bernd Linowski

[Scrunitizer]  [Overview]  [Cookbook]  [Download]  [Index]  [Linosphere]

Page generated: 1 Nov 2000
(C) by Bernd Linowski
scrunitizer@linosphere.de