📄 group___writing_test_fixture.html
字号:
<a class="anchor" name="ga1" doxytag="HelperMacros.h::CPPUNIT_TEST_SUB_SUITE" ></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_SUB_SUITE </td> <td class="md" valign="top">( </td> <td class="md" nowrap valign="top">ATestFixtureType, <tr> <td class="md" nowrap align="right"></td> <td></td> <td class="md" nowrap>ASuperClass </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><span class="keyword">public</span>: \ <span class="keyword">typedef</span> ASuperClass ParentTestFixtureType; \ <span class="keyword">private</span>: \ <a class="code" href="group___writing_test_fixture.html#ga0">CPPUNIT_TEST_SUITE</a>( ATestFixtureType ); \ ParentTestFixtureType::addTestsToSuite( baseContext )</div></pre>Begin test suite (includes parent suite). <p>This macro may only be used in a class whose parent class defines a test suite using <a class="el" href="group___writing_test_fixture.html#ga0">CPPUNIT_TEST_SUITE()</a> or <a class="el" href="group___writing_test_fixture.html#ga1">CPPUNIT_TEST_SUB_SUITE()</a>.<p>This macro begins the declaration of a test suite, in the same manner as <a class="el" href="group___writing_test_fixture.html#ga0">CPPUNIT_TEST_SUITE()</a>. In addition, the test suite of the parent is automatically inserted in the test suite being defined.<p>Here is an example:<p><pre><div class="fragment"><span class="preprocessor"> #include <<a class="code" href="_helper_macros_8h.html">cppunit/extensions/HelperMacros.h</a>></span> <span class="keyword">class </span>MySubTest : <span class="keyword">public</span> MyTest { <a class="code" href="group___writing_test_fixture.html#ga1">CPPUNIT_TEST_SUB_SUITE</a>( MySubTest, MyTest ); <a class="code" href="group___writing_test_fixture.html#ga5">CPPUNIT_TEST</a>( testAdd ); <a class="code" href="group___writing_test_fixture.html#ga5">CPPUNIT_TEST</a>( testSub ); <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> testAdd(); <span class="keywordtype">void</span> testSub(); };</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>ATestFixtureType</em> </td><td>Type of the test case class. This type <b>MUST</b> be derived from <a class="el" href="class_test_fixture.html">TestFixture</a>. </td></tr> <tr><td></td><td valign=top><em>ASuperClass</em> </td><td>Type of the parent class. </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="ga0" doxytag="HelperMacros.h::CPPUNIT_TEST_SUITE" ></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_SUITE </td> <td class="md" valign="top">( </td> <td class="md" nowrap valign="top">ATestFixtureType </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><span class="keyword">public</span>: \ <span class="keyword">typedef</span> ATestFixtureType TestFixtureType; \ \ <span class="keyword">private</span>: \ <span class="keyword">static</span> <span class="keyword">const</span> CPPUNIT_NS::TestNamer &getTestNamer__() \ { \ <span class="keyword">static</span> <a class="code" href="_test_namer_8h.html#a0">CPPUNIT_TESTNAMER_DECL</a>( testNamer, ATestFixtureType ); \ <span class="keywordflow">return</span> testNamer; \ } \ \ <span class="keyword">public</span>: \ <span class="keyword">typedef</span> CPPUNIT_NS::TestSuiteBuilderContext<TestFixtureType> \ TestSuiteBuilderContextType; \ \ <span class="keyword">static</span> <span class="keywordtype">void</span> \ addTestsToSuite( CPPUNIT_NS::TestSuiteBuilderContextBase &baseContext ) \ { \ TestSuiteBuilderContextType context( baseContext )</div></pre>Begin test suite. <p>This macro starts the declaration of a new test suite. Use <a class="el" href="group___writing_test_fixture.html#ga1">CPPUNIT_TEST_SUB_SUITE()</a> instead, if you wish to include the test suite of the parent class.<p><dl compact><dt><b>Parameters:</b></dt><dd> <table border="0" cellspacing="2" cellpadding="0"> <tr><td></td><td valign=top><em>ATestFixtureType</em> </td><td>Type of the test case class. This type <b>MUST</b> be derived from <a class="el" href="class_test_fixture.html">TestFixture</a>. </td></tr> </table></dl><dl compact><dt><b>See also:</b></dt><dd><a class="el" href="group___writing_test_fixture.html#ga1">CPPUNIT_TEST_SUB_SUITE</a>, <a class="el" href="group___writing_test_fixture.html#ga5">CPPUNIT_TEST</a>, <a class="el" href="group___writing_test_fixture.html#ga2">CPPUNIT_TEST_SUITE_END</a>, <p><a class="el" href="group___creating_test_suite.html#ga0">CPPUNIT_TEST_SUITE_REGISTRATION</a>, <a class="el" href="group___writing_test_fixture.html#ga6">CPPUNIT_TEST_EXCEPTION</a>, <a class="el" href="group___writing_test_fixture.html#ga7">CPPUNIT_TEST_FAIL</a>. </dd></dl> </td> </tr></table><a class="anchor" name="ga8" doxytag="HelperMacros.h::CPPUNIT_TEST_SUITE_ADD_CUSTOM_TESTS" ></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_SUITE_ADD_CUSTOM_TESTS </td> <td class="md" valign="top">( </td> <td class="md" nowrap valign="top">testAdderMethod </td> <td class="mdname1" valign="top" nowrap> </td> <td class="md" valign="top"> ) </td> <td class="md" nowrap> testAdderMethod( context )</td> </tr> </table> </td> </tr></table><table cellspacing=5 cellpadding=0 border=0> <tr> <td> </td> <td><p>Adds some custom test cases. <p>Use this to add one or more test cases to the fixture suite. The specified method is called with a context parameter that can be used to name, instantiate fixture, and add instantiated test case to the fixture suite. The specified method must have the following signature: <pre><div class="fragment"> <span class="keyword">static</span> <span class="keywordtype">void</span> aMethodName( TestSuiteBuilderContextType &context );</div></pre><p><code>TestSuiteBuilderContextType</code> is typedef to TestSuiteBuilderContext<TestFixtureType> declared by <a class="el" href="group___writing_test_fixture.html#ga0">CPPUNIT_TEST_SUITE()</a>.<p>Here is an example that add two custom tests:<p><pre><div class="fragment"><span class="preprocessor"> #include <<a class="code" href="_helper_macros_8h.html">cppunit/extensions/HelperMacros.h</a>></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#ga8">CPPUNIT_TEST_SUITE_ADD_CUSTOM_TESTS</a>( addTimeOutTests ); <a class="code" href="group___writing_test_fixture.html#ga2">CPPUNIT_TEST_SUITE_END</a>(); <span class="keyword">public</span>: <span class="keyword">static</span> <span class="keywordtype">void</span> addTimeOutTests( TestSuiteBuilderContextType &context ) { context.addTest( <span class="keyword">new</span> TimeOutTestCaller( context.getTestNameFor( <span class="stringliteral">"test1"</span> ) ), &MyTest::test1, context.makeFixture(), 5.0 ); context.addTest( <span class="keyword">new</span> TimeOutTestCaller( context.getTestNameFor( <span class="stringliteral">"test2"</span> ) ), &MyTest::test2, context.makeFixture(), 5.0 ); } <span class="keywordtype">void</span> test1() { <span class="comment">// Do some test that may never end...</span> } <span class="keywordtype">void</span> test2() { <span class="comment">// Do some test that may never end...</span> } };</div></pre><dl compact><dt><b>Parameters:</b></dt><dd> <table border="0" cellspacing="2" cellpadding="0"> <tr><td></td><td valign=top><em>testAdderMethod</em> </td><td>Name of the method called to add the test cases. </td></tr> </table></dl> </td> </tr></table><a class="anchor" name="ga4" doxytag="HelperMacros.h::CPPUNIT_TEST_SUITE_ADD_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_SUITE_ADD_TEST </td> <td class="md" valign="top">( </td> <td class="md" nowrap valign="top">test </td> <td class="mdname1" valign="top" nowrap> </td> <td class="md" valign="top"> ) </td> <td class="md" nowrap> context.addTest( test )</td> </tr> </table> </td> </tr></table><table cellspacing=5 cellpadding=0 border=0> <tr> <td> </td> <td><p>Add a test to the suite (for custom test macro). <p>The specified test will be added to the test suite being declared. This macro is intended for <em>advanced</em> usage, to extend CppUnit by creating new macro such as <a class="el" href="group___writing_test_fixture.html#ga6">CPPUNIT_TEST_EXCEPTION()</a>...<p>Between macro <a class="el" href="group___writing_test_fixture.html#ga0">CPPUNIT_TEST_SUITE()</a> and <a class="el" href="group___writing_test_fixture.html#ga2">CPPUNIT_TEST_SUITE_END()</a>, you can assume that the following variables can be used: <pre><div class="fragment"> <span class="keyword">typedef</span> TestSuiteBuilder<TestFixtureType> TestSuiteBuilderType; TestSuiteBuilderType &context;</div></pre><p><code>context</code> can be used to name test case, create new test fixture instance, or add test case to the test fixture suite.<p>Below is an example that show how to use this macro to create new macro to add test to the fixture suite. The macro below show how you would add a new type of test case which fails if the execution last more than a given time limit. It relies on an imaginary TimeOutTestCaller class which has an interface similar to <a class="el" href="class_test_caller.html">TestCaller</a>.<p>
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -