⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 group___writing_test_fixture.html

📁 c++开发的一个不错的工具
💻 HTML
📖 第 1 页 / 共 3 页
字号:
<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&nbsp;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&nbsp;Hierarchy</a> | <a class="qindex" href="classes.html">Alphabetical&nbsp;List</a> | <a class="qindex" href="annotated.html">Class&nbsp;List</a> | <a class="qindex" href="files.html">File&nbsp;List</a> | <a class="qindex" href="namespacemembers.html">Namespace&nbsp;Members</a> | <a class="qindex" href="functions.html">Class&nbsp;Members</a> | <a class="qindex" href="globals.html">File&nbsp;Members</a> | <a class="qindex" href="pages.html">Related&nbsp;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 &nbsp;</td><td class="memItemRight" valign=bottom><a class="el" href="_helper_macros_8h.html">HelperMacros.h</a></td></tr><tr><td class="mdescLeft">&nbsp;</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 &nbsp;</td><td class="memItemRight" valign=bottom><a class="el" href="class_test_caller.html">TestCaller&lt; Fixture &gt;</a></td></tr><tr><td class="mdescLeft">&nbsp;</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 &nbsp;</td><td class="memItemRight" valign=bottom><a class="el" href="class_test_fixture.html">TestFixture</a></td></tr><tr><td class="mdescLeft">&nbsp;</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&nbsp;</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">&nbsp;</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&nbsp;</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">&nbsp;</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&nbsp;</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">&nbsp;</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&nbsp;</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">&nbsp;</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&nbsp;</td><td class="memItemRight" valign=bottom><a class="el" href="group___writing_test_fixture.html#ga4">CPPUNIT_TEST_SUITE_ADD_TEST</a>(test)&nbsp;&nbsp;&nbsp;context.addTest( test )</td></tr><tr><td class="mdescLeft">&nbsp;</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&nbsp;</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">&nbsp;</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&nbsp;</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">&nbsp;</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&nbsp;</td><td class="memItemRight" valign=bottom><a class="el" href="group___writing_test_fixture.html#ga7">CPPUNIT_TEST_FAIL</a>(testMethod)&nbsp;&nbsp;&nbsp;CPPUNIT_TEST_EXCEPTION( testMethod, CPPUNIT_NS::Exception )</td></tr><tr><td class="mdescLeft">&nbsp;</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&nbsp;</td><td class="memItemRight" valign=bottom><a class="el" href="group___writing_test_fixture.html#ga8">CPPUNIT_TEST_SUITE_ADD_CUSTOM_TESTS</a>(testAdderMethod)&nbsp;&nbsp;&nbsp;testAdderMethod( context )</td></tr><tr><td class="mdescLeft">&nbsp;</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&nbsp;</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">&nbsp;</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">(&nbsp;</td>          <td class="md" nowrap valign="top">testMethod&nbsp;</td>          <td class="mdname1" valign="top" nowrap>          </td>          <td class="md" valign="top">&nbsp;)&nbsp;</td>          <td class="md" nowrap></td>        </tr>      </table>    </td>  </tr></table><table cellspacing=5 cellpadding=0 border=0>  <tr>    <td>      &nbsp;    </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&lt;TestFixtureType&gt;(    \                  context.getTestNameFor( #testMethod),   \                  &amp;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>&nbsp;</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">(&nbsp;</td>          <td class="md" nowrap valign="top">testMethod,         <tr>          <td class="md" nowrap align="right"></td>          <td></td>          <td class="md" nowrap>ExceptionType&nbsp;</td>          <td class="mdname1" valign="top" nowrap>          </td>          <td class="md" valign="top">&nbsp;)&nbsp;</td>          <td class="md" nowrap></td>        </tr>      </table>    </td>  </tr></table><table cellspacing=5 cellpadding=0 border=0>  <tr>    <td>      &nbsp;    </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&lt; ExceptionType &gt;(  \          <span class="keyword">new</span> CPPUNIT_NS::TestCaller&lt; TestFixtureType &gt;(             \                               context.getTestNameFor( #testMethod ),  \                               &amp;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 &lt;<a class="code" href="_helper_macros_8h.html">cppunit/extensions/HelperMacros.h</a>&gt;</span><span class="preprocessor"> #include &lt;vector&gt;</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&lt;int&gt; 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>&nbsp;</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>&nbsp;</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">(&nbsp;</td>          <td class="md" nowrap valign="top">testMethod&nbsp;</td>          <td class="mdname1" valign="top" nowrap>          </td>          <td class="md" valign="top">&nbsp;)&nbsp;</td>          <td class="md" nowrap>&nbsp;&nbsp;&nbsp;CPPUNIT_TEST_EXCEPTION( testMethod, CPPUNIT_NS::Exception )</td>        </tr>      </table>    </td>  </tr></table><table cellspacing=5 cellpadding=0 border=0>  <tr>    <td>      &nbsp;    </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 + -