📄 group___writing_test_fixture.html
字号:
<html><head><title>CppUnit - The Unit Testing Library</title><link href="doxygen.css" rel="stylesheet" type="text/css"></head><body bgcolor="#ffffff"> <table width="100%"> <tr> <td width="40%" align="left" valign="center"> <a href="http://sourceforge.net/projects/cppunit"> CppUnit project page </a> </td> <td> <a href="FAQ">FAQ</a> </td> <td width="40%" align="right" valign="center"> <a href="http://cppunit.sourceforge.net">CppUnit home page</a> </td> </tr></table><hr><!-- Generated by Doxygen 1.3.7 --><div class="qindex"><a class="qindex" href="index.html">Main Page</a> | <a class="qindex" href="modules.html">Modules</a> | <a class="qindex" href="namespaces.html">Namespace List</a> | <a class="qindex" href="hierarchy.html">Class Hierarchy</a> | <a class="qindex" href="classes.html">Alphabetical List</a> | <a class="qindex" href="annotated.html">Class List</a> | <a class="qindex" href="files.html">File List</a> | <a class="qindex" href="namespacemembers.html">Namespace Members</a> | <a class="qindex" href="functions.html">Class Members</a> | <a class="qindex" href="globals.html">File Members</a> | <a class="qindex" href="pages.html">Related Pages</a></div><h1>Writing test fixture</h1><table border=0 cellpadding=0 cellspacing=0><tr><td></td></tr><tr><td colspan=2><br><h2>Files</h2></td></tr><tr><td class="memItemLeft" nowrap align=right valign=top>file </td><td class="memItemRight" valign=bottom><a class="el" href="_helper_macros_8h.html">HelperMacros.h</a></td></tr><tr><td class="mdescLeft"> </td><td class="mdescRight">Macros intended to ease the definition of test suites. <br><br></td></tr><p><tr><td colspan=2><br><h2>Classes</h2></td></tr><tr><td class="memItemLeft" nowrap align=right valign=top>class </td><td class="memItemRight" valign=bottom><a class="el" href="class_test_caller.html">TestCaller< Fixture ></a></td></tr><tr><td class="mdescLeft"> </td><td class="mdescRight">Generate a test case from a fixture method. <a href="class_test_caller.html#_details">More...</a><br><br></td></tr><tr><td class="memItemLeft" nowrap align=right valign=top>class </td><td class="memItemRight" valign=bottom><a class="el" href="class_test_fixture.html">TestFixture</a></td></tr><tr><td class="mdescLeft"> </td><td class="mdescRight">Wraps a test case with setUp and tearDown methods. <a href="class_test_fixture.html#_details">More...</a><br><br></td></tr><tr><td colspan=2><br><h2>Defines</h2></td></tr><tr><td class="memItemLeft" nowrap align=right valign=top>#define </td><td class="memItemRight" valign=bottom><a class="el" href="group___writing_test_fixture.html#ga0">CPPUNIT_TEST_SUITE</a>(ATestFixtureType)</td></tr><tr><td class="mdescLeft"> </td><td class="mdescRight">Begin test suite. <a href="#ga0"></a><br><br></td></tr><tr><td class="memItemLeft" nowrap align=right valign=top>#define </td><td class="memItemRight" valign=bottom><a class="el" href="group___writing_test_fixture.html#ga1">CPPUNIT_TEST_SUB_SUITE</a>(ATestFixtureType, ASuperClass)</td></tr><tr><td class="mdescLeft"> </td><td class="mdescRight">Begin test suite (includes parent suite). <a href="#ga1"></a><br><br></td></tr><tr><td class="memItemLeft" nowrap align=right valign=top>#define </td><td class="memItemRight" valign=bottom><a class="el" href="group___writing_test_fixture.html#ga2">CPPUNIT_TEST_SUITE_END</a>()</td></tr><tr><td class="mdescLeft"> </td><td class="mdescRight">End declaration of the test suite. <a href="#ga2"></a><br><br></td></tr><tr><td class="memItemLeft" nowrap align=right valign=top>#define </td><td class="memItemRight" valign=bottom><a class="el" href="group___writing_test_fixture.html#ga3">CPPUNIT_TEST_SUITE_END_ABSTRACT</a>()</td></tr><tr><td class="mdescLeft"> </td><td class="mdescRight">End declaration of an abstract test suite. <a href="#ga3"></a><br><br></td></tr><tr><td class="memItemLeft" nowrap align=right valign=top>#define </td><td class="memItemRight" valign=bottom><a class="el" href="group___writing_test_fixture.html#ga4">CPPUNIT_TEST_SUITE_ADD_TEST</a>(test) context.addTest( test )</td></tr><tr><td class="mdescLeft"> </td><td class="mdescRight">Add a test to the suite (for custom test macro). <a href="#ga4"></a><br><br></td></tr><tr><td class="memItemLeft" nowrap align=right valign=top>#define </td><td class="memItemRight" valign=bottom><a class="el" href="group___writing_test_fixture.html#ga5">CPPUNIT_TEST</a>(testMethod)</td></tr><tr><td class="mdescLeft"> </td><td class="mdescRight">Add a method to the suite. <a href="#ga5"></a><br><br></td></tr><tr><td class="memItemLeft" nowrap align=right valign=top>#define </td><td class="memItemRight" valign=bottom><a class="el" href="group___writing_test_fixture.html#ga6">CPPUNIT_TEST_EXCEPTION</a>(testMethod, ExceptionType)</td></tr><tr><td class="mdescLeft"> </td><td class="mdescRight">Add a test which fail if the specified exception is not caught. <a href="#ga6"></a><br><br></td></tr><tr><td class="memItemLeft" nowrap align=right valign=top>#define </td><td class="memItemRight" valign=bottom><a class="el" href="group___writing_test_fixture.html#ga7">CPPUNIT_TEST_FAIL</a>(testMethod) CPPUNIT_TEST_EXCEPTION( testMethod, CPPUNIT_NS::Exception )</td></tr><tr><td class="mdescLeft"> </td><td class="mdescRight">Adds a test case which is excepted to fail. <a href="#ga7"></a><br><br></td></tr><tr><td class="memItemLeft" nowrap align=right valign=top>#define </td><td class="memItemRight" valign=bottom><a class="el" href="group___writing_test_fixture.html#ga8">CPPUNIT_TEST_SUITE_ADD_CUSTOM_TESTS</a>(testAdderMethod) testAdderMethod( context )</td></tr><tr><td class="mdescLeft"> </td><td class="mdescRight">Adds some custom test cases. <a href="#ga8"></a><br><br></td></tr><tr><td class="memItemLeft" nowrap align=right valign=top>#define </td><td class="memItemRight" valign=bottom><a class="el" href="group___writing_test_fixture.html#ga9">CPPUNIT_TEST_SUITE_PROPERTY</a>(APropertyKey, APropertyValue)</td></tr><tr><td class="mdescLeft"> </td><td class="mdescRight">Adds a property to the test suite builder context. <a href="#ga9"></a><br><br></td></tr></table><hr><h2>Define Documentation</h2><a class="anchor" name="ga5" doxytag="HelperMacros.h::CPPUNIT_TEST" ></a><p><table class="mdTable" width="100%" cellpadding="2" cellspacing="0"> <tr> <td class="mdRow"> <table cellpadding="0" cellspacing="0" border="0"> <tr> <td class="md" nowrap valign="top"> #define CPPUNIT_TEST </td> <td class="md" valign="top">( </td> <td class="md" nowrap valign="top">testMethod </td> <td class="mdname1" valign="top" nowrap> </td> <td class="md" valign="top"> ) </td> <td class="md" nowrap></td> </tr> </table> </td> </tr></table><table cellspacing=5 cellpadding=0 border=0> <tr> <td> </td> <td><p><b>Value:</b><pre class="fragment"><div><a class="code" href="group___writing_test_fixture.html#ga4">CPPUNIT_TEST_SUITE_ADD_TEST</a>( \ ( <span class="keyword">new</span> CPPUNIT_NS::TestCaller<TestFixtureType>( \ context.getTestNameFor( #testMethod), \ &TestFixtureType::testMethod, \ context.makeFixture() ) ) )</div></pre>Add a method to the suite. <p><dl compact><dt><b>Parameters:</b></dt><dd> <table border="0" cellspacing="2" cellpadding="0"> <tr><td></td><td valign=top><em>testMethod</em> </td><td>Name of the method of the test case to add to the suite. The signature of the method must be of type: void testMethod(); </td></tr> </table></dl><dl compact><dt><b>See also:</b></dt><dd><a class="el" href="group___writing_test_fixture.html#ga0">CPPUNIT_TEST_SUITE</a>. </dd></dl> </td> </tr></table><a class="anchor" name="ga6" doxytag="HelperMacros.h::CPPUNIT_TEST_EXCEPTION" ></a><p><table class="mdTable" width="100%" cellpadding="2" cellspacing="0"> <tr> <td class="mdRow"> <table cellpadding="0" cellspacing="0" border="0"> <tr> <td class="md" nowrap valign="top"> #define CPPUNIT_TEST_EXCEPTION </td> <td class="md" valign="top">( </td> <td class="md" nowrap valign="top">testMethod, <tr> <td class="md" nowrap align="right"></td> <td></td> <td class="md" nowrap>ExceptionType </td> <td class="mdname1" valign="top" nowrap> </td> <td class="md" valign="top"> ) </td> <td class="md" nowrap></td> </tr> </table> </td> </tr></table><table cellspacing=5 cellpadding=0 border=0> <tr> <td> </td> <td><p><b>Value:</b><pre class="fragment"><div><a class="code" href="group___writing_test_fixture.html#ga4">CPPUNIT_TEST_SUITE_ADD_TEST</a>( \ (<span class="keyword">new</span> CPPUNIT_NS::ExceptionTestCaseDecorator< ExceptionType >( \ <span class="keyword">new</span> CPPUNIT_NS::TestCaller< TestFixtureType >( \ context.getTestNameFor( #testMethod ), \ &TestFixtureType::testMethod, \ context.makeFixture() ) ) ) )</div></pre>Add a test which fail if the specified exception is not caught. <p>Example: <pre><div class="fragment"><span class="preprocessor"> #include <<a class="code" href="_helper_macros_8h.html">cppunit/extensions/HelperMacros.h</a>></span><span class="preprocessor"> #include <vector></span> <span class="keyword">class </span>MyTest : <span class="keyword">public</span> CppUnit::<a class="code" href="class_test_fixture.html">TestFixture</a> { <a class="code" href="group___writing_test_fixture.html#ga0">CPPUNIT_TEST_SUITE</a>( MyTest ); <a class="code" href="group___writing_test_fixture.html#ga6">CPPUNIT_TEST_EXCEPTION</a>( testVectorAtThrow, std::invalid_argument ); <a class="code" href="group___writing_test_fixture.html#ga2">CPPUNIT_TEST_SUITE_END</a>(); <span class="keyword">public</span>: <span class="keywordtype">void</span> testVectorAtThrow() { std::vector<int> v; v.at( 1 ); <span class="comment">// must throw exception std::invalid_argument</span> } };</div></pre><p><dl compact><dt><b>Parameters:</b></dt><dd> <table border="0" cellspacing="2" cellpadding="0"> <tr><td></td><td valign=top><em>testMethod</em> </td><td>Name of the method of the test case to add to the suite. </td></tr> <tr><td></td><td valign=top><em>ExceptionType</em> </td><td>Type of the exception that must be thrown by the test method. </td></tr> </table></dl><dl compact><dt><b><a class="el" href="deprecated.html#_deprecated000001">Deprecated:</a></b></dt><dd>Use the assertion macro CPPUNIT_ASSERT_THROW instead. </dd></dl> </td> </tr></table><a class="anchor" name="ga7" doxytag="HelperMacros.h::CPPUNIT_TEST_FAIL" ></a><p><table class="mdTable" width="100%" cellpadding="2" cellspacing="0"> <tr> <td class="mdRow"> <table cellpadding="0" cellspacing="0" border="0"> <tr> <td class="md" nowrap valign="top"> #define CPPUNIT_TEST_FAIL </td> <td class="md" valign="top">( </td> <td class="md" nowrap valign="top">testMethod </td> <td class="mdname1" valign="top" nowrap> </td> <td class="md" valign="top"> ) </td> <td class="md" nowrap> CPPUNIT_TEST_EXCEPTION( testMethod, CPPUNIT_NS::Exception )</td> </tr> </table> </td> </tr></table><table cellspacing=5 cellpadding=0 border=0> <tr> <td> </td> <td><p>Adds a test case which is excepted to fail. <p>The added test case expect an assertion to fail. You usually used that type of test case when testing custom assertion macros.<p><pre><div class="fragment"> <a class="code" href="group___writing_test_fixture.html#ga7">CPPUNIT_TEST_FAIL</a>( testAssertFalseFail ); <span class="keywordtype">void</span> testAssertFalseFail() { <a class="code" href="group___assertions.html#ga0">CPPUNIT_ASSERT</a>( <span class="keyword">false</span> ); }</div></pre><dl compact><dt><b>See also:</b></dt><dd><a class="el" href="group___creating_new_assertions.html">CreatingNewAssertions</a>. </dd></dl><dl compact><dt><b><a class="el" href="deprecated.html#_deprecated000002">Deprecated:</a></b></dt><dd>Use the assertion macro CPPUNIT_ASSERT_ASSERTION_FAIL instead. </dd></dl> </td> </tr></table>
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -