CppUnit project page | FAQ | CppUnit home page |
#include <ExceptionTestCaseDecorator.h>
Inheritance diagram for ExceptionTestCaseDecorator< ExpectedException >:
Public Types | |
typedef ExpectedException | ExpectedExceptionType |
Public Member Functions | |
ExceptionTestCaseDecorator (TestCase *test) | |
Decorates the specified test. | |
void | runTest () |
Checks that the expected exception is thrown by the decorated test. is thrown. | |
Private Member Functions | |
virtual void | checkException (ExpectedExceptionType &e) |
Called when the exception is caught. |
A decorator used to assert that a specific test case should throw an exception of a given type.
You should use this class only if you need to check the exception object state (that a specific cause is set for example). If you don't need to do that, you might consider using CPPUNIT_TEST_EXCEPTION() instead.
Intended use is to subclass and override checkException(). Example:
class NetworkErrorTestCaseDecorator : public ExceptionTestCaseDecorator<NetworkError> { public: NetworkErrorTestCaseDecorator( NetworkError::Cause expectedCause ) : m_expectedCause( expectedCause ) { } private: void checkException( ExpectedExceptionType &e ) { CPPUNIT_ASSERT_EQUAL( m_expectedCause, e.getCause() ); } NetworkError::Cause m_expectedCause; };
|
|
|
Decorates the specified test.
|
|
Called when the exception is caught. Should be overriden to check the exception. |
|
Checks that the expected exception is thrown by the decorated test. is thrown. Calls the decorated test runTest() and checks that an exception of type ExpectedException is thrown. Call checkException() passing the exception that was caught so that some assertions can be made if needed. Reimplemented from TestCaseDecorator. |
hosts this site. |
Send comments to: CppUnit Developers |