Using Verifying Test Cases

Having every object correctly verified is something you might regularly forget. To support this a bit, there is a special class mockpp::VerifyingTestCase. Using it ensures that all expectations are verifyied at the end of the call. It also reminds you, if you have not registered any object. This also implies that you have to take another registering macro if you don't want the automatic verification for a certain method.

The class is based on CppUnit and works very similarly. There is a macro for verifying and non-verifying test methods as well as for the (in CppUnit deprecated) tests that check for thrown eceptions.

class VerifyingCalculator_test : public mockpp::VerifyingTestCase
   CPPUNIT_TEST_SUITE( VerifyingCalculator_test );
     MOCKPP_TEST_EXCEPTION(test_fail_no_verify, mockpp::AssertionFailedError);
     MOCKPP_VERIFYING_TEST_EXCEPTION(test_fail, mockpp::AssertionFailedError);

For automatic verification all your expectations have to be created on the heap with new and registered with the surrounding mock object. This is a bit inconvenient but necessary to extend the lifetime of the expectations beyond the return of the test method.

void VerifyingCalculator_test::test_ok()
  mockpp::ExpectationValue<int> *ev = new mockpp::ExpectationValue<int> ("ev") ;


verifying.cpp contains the complete source code.

Table of contents

 All Classes Namespaces Files Functions Variables Typedefs Friends Defines

Generated on Tue Jan 5 18:03:33 2010 for mockpp-tutorial by  doxygen 1.6.1