1 /* -*- Indented-Text -*- */
2 /* Copyright (C) 2003, 2010 TSUTSUMI Kikuo.
3 This file is part of the CCUnit Library.
5 The CCUnit Library is free software; you can redistribute it and/or
6 modify it under the terms of the GNU Lesser General Public License
7 as published by the Free Software Foundation; either version 2.1 of
8 the License, or (at your option) any later version.
10 The CCUnit Library is distributed in the hope that it will be
11 useful, but WITHOUT ANY WARRANTY; without even the implied warranty
12 of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 GNU Lesser General Public License for more details.
15 You should have received a copy of the GNU Lesser General Public
16 License along with the CCUnit Library; see the file COPYING.LESSER.
17 If not, see <http://www.gnu.org/licenses/>
22 @page cookbook CCUnit Cookbook
24 @page cookbook CCUnit ¥¯¥Ã¥¯¥Ö¥Ã¥¯
28 Here is a short cookbook to help you get started.
30 ¤³¤ì¤Ï CCUnit ¤ò»È¤¤»Ï¤á¤ë¤Ë¤¢¤¿¤Ã¤Æ¡¢
31 Íý²ò¤Î½õ¤±¤È¤Ê¤ë¤è¤¦¤Êû¤¤¥¯¥Ã¥¯¥Ö¥Ã¥¯¤Ç¤¹¡£
34 [see also <a href="../ja/cookbook.html">Japanese</a> documents]
36 [see also <a href="../../cookbook.html">English</a> documents]
40 @section simple_test_case Simple Test Case
42 @section simple_test_case ¥·¥ó¥×¥ë¤Ê¥Æ¥¹¥È¥±¡¼¥¹
46 Tests in <b>CCUnit</b> can be run automatically. They are
47 easy to set up and once you have written them, they are
48 always there to help you keep confidence in the quality of
51 CCUnit¤ò»È¤Ã¤¿¥Æ¥¹¥È¤Ï¼«Æ°Åª¤Ë¼Â¹Ô¤¹¤ë¤³¤È¤¬¤Ç¤¤Þ¤¹¡£
52 CCUnit ¤Î¥Æ¥¹¥È¤Ï´Êñ¤Ë¥»¥Ã¥È¥¢¥Ã¥×¤¹¤ë¤³¤È¤¬¤Ç¤¡¢
53 °ìÅ٥ƥ¹¥È¤ò½ñ¤¤¤Æ¤·¤Þ¤¨¤Ð¡¢
54 ¤¤¤Ä¤Ç¤â¥×¥í¥°¥é¥à¤ÎÉʼÁ¤ò¿®Íê¤Ç¤¤ë¤â¤Î¤ËÊݤĤ³¤È¤¬¤Ç¤¤ë¤Ç¤·¤ç¤¦¡£
58 To make a simple test, here is what you do:
60 ñ½ã¤Ê¥Æ¥¹¥È¤òºî¤ë¤Ë¤Ï¡¢¼¡¤Î¤è¤¦¤Ë¤·¤Þ¤¹¡£
64 <li> @english Create a test function
65 @japanese ¥Æ¥¹¥È´Ø¿ô¤òºî¤ê¤Þ¤¹¡£
68 <li> @english When you want to check a value, call
69 @link CCUNIT_ASSERT() CCUNIT_ASSERT(bool) @endlink
70 and pass a bool that is true if the test succeeds
72 ASSERT macro is listed in others as well in
73 @link Assertions Making assertions @endlink.
75 Ãͤò¥Á¥§¥Ã¥¯¤·¤¿¤¤¾ì¹ç¤Ï¡¢
76 @link CCUNIT_ASSERT() CCUNIT_ASSERT(bool) @endlink
78 ¥Æ¥¹¥È¤¬À®¸ù¤¹¤ë¤Ê¤é¿¿¤òÊÖ¤¹¤è¤¦¤Ê¿¿µ¶ÃͤòÅϤ·¤Þ¤¹¡£
80 ASSERT ´Ø·¸¤Î¥Þ¥¯¥í¤Ï¾¤Ë¤â
81 @link Assertions ¥¢¥µ¡¼¥È¤ÎÀë¸À @endlink
82 ¤Ë¥ê¥¹¥È¤·¤Æ¤¢¤ê¤Þ¤¹¡£
88 For example, to test that the sum of two complex number
89 which is the sum of the values of two complex numbers,
90 write (This sample program is in the @c examples/complex directory):
92 Î㤨¤Ð¡¢´Êñ¤ÊÊ£ÁÇ¿ô¤Î¥é¥¤¥Ö¥é¥ê¤ò¥Æ¥¹¥È¤¹¤ë¤³¤È¤òÎã¤Ë¤È¤Ã¤Æ¤ß¤Þ¤·¤ç¤¦¡£
93 ¡Ê¤³¤³¤Ç»ÈÍѤ¹¤ë@ref sample_programs¤Ï
94 examples/complex ¥Ç¥£¥ì¥¯¥È¥ê¤Ë¤¢¤ê¤Þ¤¹¡£¡Ë
95 Ê£ÁÇ¿ô¤ò½é´ü²½¤¹¤ë¤³¤È¤¬¤Ç¤¤¿¤«¤ò¥Æ¥¹¥È¤·¤¿¤ê¡¢
96 Æó¤Ä¤ÎÊ£ÁÇ¿ô¤¬Åù¤·¤¤¤«¤ò¥Æ¥¹¥È¤¹¤ë¤È¤·¤Þ¤¹¡£
99 @dontinclude complex/testComplex.c
101 @skip test_complex_new
103 @skip test_complex_equals
108 ¤³¤ÎÆó¤Ä¤Î¥Æ¥¹¥È´Ø¿ô¤ò¤Þ¤È¤á¤Æ¤Ò¤È¤Ä¤Î¥Æ¥¹¥È¥±¡¼¥¹¤Ë¤·¤Æ¼Â¹Ô¤¹¤ë¤³¤È¤¬¤Ç¤¤Þ¤¹¡£
111 @dontinclude complex/runTestCase.c
113 @skip CCUnitTestCase.h
114 @until CCUnitTestResult.h
118 ɬÍפʥإåÀ¥Õ¥¡¥¤¥ë¤ò¥¤¥ó¥¯¥ë¡¼¥É¤·¤Þ¤¹¡£
122 @until ccunit_newTestCase
126 ¤Þ¤º¥Æ¥¹¥È¥±¡¼¥¹¤Ë¥á¥â¥ê¤ò³ä¤êÅö¤Æ¤Þ¤¹¡£
129 @until test_complex_equals);
133 ¤½¤·¤Æ¥Æ¥¹¥È¥±¡¼¥¹¤Ë¥Æ¥¹¥È´Ø¿ô¤òÅÐÏ¿¤·¤Þ¤¹¡£
134 ɽÌÀ (ASSERT) ¤¬¼ºÇÔ¤·¤¿»þ¤Ëɽ¼¨¤¹¤ë¤¿¤á¤Î´Ø¿ô̾¤È´Ø¿ô¤ÎÀâÌÀ¤ò°ì½ï¤Ë»ØÄꤷ¤Æ¤¤¤Þ¤¹¡£
141 ¥Æ¥¹¥È¥±¡¼¥¹¤ò¼Â¹Ô¤·¡¢
149 ³ä¤êÅö¤Æ¤¿¥á¥â¥ê¤ò²òÊü¤·¡¢
154 The sample code made in the above is in the directory <code>examples/complex</code>,
155 the files are @c testComplex.c and <code>runTestCase.c</code>.
157 ¤³¤³¤Þ¤Ç¤Î¥µ¥ó¥×¥ë¥³¡¼¥É¤Ï¡¢@c examples/complex ¥Ç¥£¥ì¥¯¥È¥ê¤Î
158 <code>testComplex.c, runTestCase.c</code> ¤Ë¤¢¤ê¤Þ¤¹¡£
160 ¥³¥ó¥Ñ¥¤¥ë¤ª¤è¤Ó¼Â¹Ô¤¹¤ë¤Ë¤Ï¡¢¼¡¤Î¤è¤¦¤Ë¤·¤Þ¤¹¡£
164 $ gcc -o runTestCase runTestCase.c testComplex.c complex.c -lccunit
171 When the test case is run, that specific test functions
172 will be run. This is not a useful thing to do, however, as
173 no diagnostics will be displayed. One will normally use a
174 @link ExecutingTest TestRunner @endlink to
177 ¥Æ¥¹¥È¥±¡¼¥¹¤¬¼Â¹Ô¤µ¤ì¤ë¤È¡¢
178 »ØÄꤷ¤¿¥Æ¥¹¥È´Ø¿ô¤¬¸Æ¤Ó½Ð¤µ¤ì¤Þ¤¹¡£
179 ¤³¤ì¤Ï¤Þ¤À¤¢¤Þ¤êÊØÍø¤Ç¤Ï¤¢¤ê¤Þ¤»¤ó¡¢
180 ¤Ê¤¼¤Ê¤é¡¢¿ÇÃǤ¬É½¼¨¤µ¤ì¤Ê¤¤¤«¤é¤Ç¤¹¡£
181 Ä̾ï¤Ï @link ExecutingTest TestRunner @endlink
186 @section test_runner TestRunner
188 @section test_runner ¥Æ¥¹¥È¥é¥ó¥Ê¡¼
192 How do you run your tests and collect their results?
193 The TestCase store result of own tests into
194 the @link CCUnitTestResult TestResult @endlink.
196 ¥Æ¥¹¥È¤ò¼Â¹Ô¤·¤¿¤È¤¤Ë¡¢¤É¤¦¤ä¤Ã¤Æ¤½¤Î·ë²Ì¤ò½¸¤á¤¿¤éÎɤ¤¤Ç¤·¤ç¤¦¤«¡£
197 ¥Æ¥¹¥È¥±¡¼¥¹¤Ï¥Æ¥¹¥È´Ø¿ô¤Î¼Â¹Ô·ë²Ì
198 @link CCUnitTestFailure TestFailure @endlink ¤ò
199 @link CCUnitTestResult TestResult @endlink ¤Ë³ÊǼ¤·¤Þ¤¹¡£
200 Ʊ»þ¤Ë¥Æ¥¹¥È¤Î¼Â¹Ô¾õ¶·¤ò @link CCUnitTestRunner TestRunner @endlink
206 node [ fontsize=9, fontname=Helvetica ]
209 edge [ fontsize=9, fontname=Courier ]
210 TestCase -> TestResult [ label="TestFailure", style=dotted, arrowhead=vee ];
212 edge [ fontsize=9, dir=back ]
213 TestRunner -> TestCase [ label="Notify", fontname=Times,
214 style=dotted, arrowhead=vee ];
215 TestRunner -> TestResult [ arrowtail=none ];
216 TestCase -> "TestFunc 1..n";
217 TestResult -> "TestFailure 0..m" [ arrowtail=diamond ];
222 Once you have a test suite, you'll want to run it. %CCUnit
223 provides @link ExecutingTest TestRunner @endlink
224 to define the suite to be run and to display
227 °ì¤Ä¥Æ¥¹¥È¥±¡¼¥¹¤ò½ñ¤¤¤¿¤é¡¢
228 ¤½¤ì¤ò¼Â¹Ô¤·¤¿¤¤¤Ç¤·¤ç¤¦¡£
229 CCUnit ¤Ï¥Æ¥¹¥È¥±¡¼¥¹¤ò¥Æ¥¹¥È¥¹¡¼¥Ä¤Ë¤Þ¤È¤á¤Æ¤ë¤³¤È¤Ç¤³¤ì¤é¤ò¼Â¹Ô¤·¡¢
230 ·ë²Ì¤òɽ¼¨¤¹¤ë¤¿¤á¤Î @link ExecutingTest TestRunner @endlink ¤òÄ󶡤·¤Þ¤¹¡£
234 To use the @link CCUnitTestRunner TestRunner @endlink,
235 include the header files for the tests in runTestCaseRunner.c:
237 @link CCUnitTestRunner TestRunner @endlink ¤ò»ÈÍѤ¹¤ë¤Ë¤Ï¡¢
238 Î㤨¤Ð runTestCaseRunner.c ¤Ç¥Æ¥¹¥È¤Î¤¿¤á¤Î¥Õ¥¡¥¤¥ë¤Î¥Ø¥Ã¥À¤ò¥¤¥ó¥¯¥ë¡¼¥É¤·¤Þ¤¹¡£
241 @dontinclude complex/runTestCaseRunner.c
244 @until CCUnitTestRunner.h
246 @until ccunit_addTestCase
250 ¤Þ¤º TestSuite ¤òºîÀ®¤·¡¢
251 ¤½¤ì¤Ë TestCase ¤òÅÐÏ¿¤·¤Þ¤¹¡£
258 @link ccunit_runTestRunner()
259 ccunit_runTestRunner (CCUnitTestRunner*, CCUnitTestSuite *) @endlink
260 in the <code>main()</code> function:
262 ¤½¤·¤Æ @link ccunit_runTestRunner()
263 ccunit_runTestRunner (CCUnitTestRunner*, CCUnitTestSuite *) @endlink
267 @until deleteTestCase
271 ³ä¤êÅö¤Æ¤¿¥á¥â¥ê¤ò²òÊü¤·¤Þ¤¹¡£
272 ¤¿¤À¤·¡¢@c testCase ¤Ï @c suite ¤ËÅÐÏ¿¤·¤Æ¤¢¤ë¤Î¤Ç¡¢
273 @c suite ¤ò²òÊü¤¹¤ë»þ¤Ë°ì½ï¤Ë²òÊü¤µ¤ì¤Þ¤¹¡£
274 ¤½¤Î¤¿¤á @c testCase ¤Ï¤³¤³¤Ç²òÊü¤¹¤ëɬÍפ¬¤¢¤ê¤Þ¤»¤ó¡£
275 ²òÊü¤·¤è¤¦¤È¤¹¤ë¤È Bus error ¤Ê¤É¤Ë¤Ê¤ê¤Þ¤¹¤Î¤ÇÃí°Õ¤·¤Æ¤¯¤À¤µ¤¤¡£
280 The sample code made in the above is in the directory <code>examples/complex</code>,
281 the files <code>testComplex.c, complexTestSuite.c</code> and <code>runTestRunner.c</code>.
283 ¤³¤³¤Þ¤Ç¤Î¥µ¥ó¥×¥ë¥³¡¼¥É¤Ï¡¢<code>examples/complex</code> ¥Ç¥£¥ì¥¯¥È¥ê¤Î
284 <code>runTestCaseRunner.c</code>
287 ¥³¥ó¥Ñ¥¤¥ë¤ª¤è¤Ó¼Â¹Ô¤¹¤ë¤Ë¤Ï¡¢¼¡¤Î¤è¤¦¤Ë¤·¤Þ¤¹¡£
291 $ gcc -I. -o runTestCaseRunner runTestCaseRunner.c testComplex.c complex.c -lccunit
292 $ ./runTestCaseRunner
300 The @link ExecutingTest TestRunner @endlink will run the tests.
301 If all the tests pass, you'll get an informative message.
302 If any fail, you'll get the following information:
304 @link ExecutingTest TestRunner @endlink ¤Ï¥Æ¥¹¥È¤ò¼Â¹Ô¤·¤Þ¤¹¡£
305 ¤â¤·¤¹¤Ù¤Æ¤Î¥Æ¥¹¥È¤¬¥Ñ¥¹¤¹¤ì¤Ð¡¢¤½¤Î¾ðÊó¤Î¥á¥Ã¥»¡¼¥¸¤¬É½¼¨¤µ¤ì¤Þ¤¹¡£
306 ¾å¤ÎÎã¤Ç¤Ï¡¢ºÇ½é¤Î¡Ö<code>..</code>¡×¤Ï¼Â¹Ô¤·¤¿¥Æ¥¹¥È¥±¡¼¥¹¤Ç¤¹¡£
307 ¼Â¹Ô¤¹¤ëľÁ°¤Ë¡Ö<code>.</code>¡×¤¬½ÐÎϤµ¤ì¤Þ¤¹¡£
308 Á´¤Æ¤Î¥Æ¥¹¥È¥±¡¼¥¹¤Î¼Â¹Ô¤¬½ªÎ»¤¹¤ë¤È¡¢
309 ¼Â¹Ô¤Ë¤«¤«¤Ã¤¿»þ´Ö¤È¼Â¹Ô¤·¤¿¥Æ¥¹¥È¥±¡¼¥¹¤Î¿ô¤¬É½¼¨¤µ¤ì¤Þ¤¹¡£
311 ¤É¤ì¤«¤¬¼ºÇÔ¤¹¤ì¤Ð¡¢¤½¤ì¤Ë¤Ä¤¤¤Æ°Ê²¼¤Î¤è¤¦¤Ê¾ðÊó¤¬É½¼¨¤µ¤ì¤Þ¤¹¡£
316 The name of the source file that contains the test
318 ¥Æ¥¹¥È¤ò´Þ¤ó¤Ç¤¤¤ë¥½¡¼¥¹¥Õ¥¡¥¤¥ë̾
322 The line number where the failure occurred
328 The name of the test case that failed
330 ¼ºÇÔ¤·¤¿¥Æ¥¹¥È¥±¡¼¥¹¤Î̾Á°
334 All of the text inside the call to
335 <code>CCUNIT_ASSERT ()</code> which detected the failure
337 ¼ºÇÔ¤ò¸¡ÃΤ·¤¿<code>CCUNIT_ASSERT ()</code>¤¬¸Æ¤Ó½Ð¤µ¤ì¤¿»þ¤Î¾ò·ï¤Îʸ»úÎó¡£
344 »î¤·¤Ë @c testComplex.c ¤Î¥Æ¥¹¥È¥±¡¼¥¹¤Ç¤ï¤¶¤È´Ö°ã¤¨¤Æ¤ß¤Þ¤·¤ç¤¦¡£
348 void test_complex_equals ()
351 CCUNIT_ASSERT (complex_equals (c10_1, c10_1_2));
352 /*CCUNIT_ASSERT (complex_equals (c10_1, c1_1) == 0);*/
353 CCUNIT_ASSERT (complex_equals (c10_1, c1_1) != 0);
359 $ gcc -I. -o runTestCaseRunner runTestCaseRunner.c testComplex.c complex.c -lccunit
368 testComplex.c:46: complex equals test:
369 complex_equals (c10_1, c1_1) != 0
374 ¤³¤ÎÎã¤Ç¤Ï¥Æ¥¹¥È¥±¡¼¥¹¤ò 2 ¸Ä¼Â¹Ô¤·¤Æ¡¢
375 ¤Ò¤È¤Ä¤Î¥Æ¥¹¥È¥±¡¼¥¹¤Ç¼ºÇÔ¤·¤Æ¤¤¤ë¤³¤È¤¬¤ï¤«¤ê¤Þ¤¹¡£
376 ºÇ½é¤Î¡Ö<code>..F</code>¡×¤Ç¤Ï¡¢
377 ¤Õ¤¿¤ÄÌܤΥƥ¹¥È¥±¡¼¥¹¤¬¼ºÇÔ¤·¤Æ¤¤¤ë¤³¤È¤ò¤¢¤é¤ï¤·¤Æ¤¤¤Þ¤¹¡£
380 ¼ºÇÔ¤·¤¿¥Õ¥¡¥¤¥ë̾¡¢¹ÔÈֹ桢¥Æ¥¹¥È¥±¡¼¥¹¤Î̾Á° (<code>complex equals test</code>)¡¢
381 ɽÌÀ¤·¤¿¾ò·ï¤Îʸ»úÎó (<code>complex_equals (c10_1, c1_1) != 0</code>) ¤¬É½¼¨¤µ¤ì¤Þ¤¹¡£
385 That was a very simple test. Ordinarily, you'll have many
386 little test cases that you'll want to run on the same set of
387 objects. To do this, use global variables.
389 ¤³¤ì¤ÏÂçÊÑñ½ã¤Ê¥Æ¥¹¥È¤Ç¤¹¡£
391 ¤¿¤¯¤µ¤ó¤Î¾®¤µ¤Ê¥Æ¥¹¥È´Ø¿ô¤òºî¤Ã¤Æ¡¢
392 Ʊ¤¸¤è¤¦¤Ê¥Ç¡¼¥¿¤Î½¸¤Þ¤ê¤ò»È¤Ã¤Æ¥Æ¥¹¥È¤ò¹Ô¤¦¤Ç¤·¤ç¤¦¡£
393 ¤Ä¤Þ¤ê³Æ¥Æ¥¹¥È´Ø¿ô¶¦Ä̤Υ°¥í¡¼¥Ð¥ëÊÑ¿ô¤ò»È¤¦¤³¤È¤Ë¤Ê¤ê¤Þ¤¹¡£
397 @section setUp_and_tearDown setUp and tearDown
399 @section setUp_and_tearDown setUp ¤È tearDown
403 What if you have two or more tests that operate on the same
404 similar set of objects?
406 ¤â¤·Ê£¿ô¤Î¥Æ¥¹¥È´Ø¿ô¤¬¤¢¤ë¤Ê¤é¡¢
407 Ʊ¤¸¥Ç¡¼¥¿¤Î½¸¤Þ¤ê¤ò¤¤¤¯¤Ä¤«»È¤¦¤Î¤Ç¤Ï¤Ê¤¤¤Ç¤·¤ç¤¦¤«¡£
412 node [ fontsize=9, fontname=Helvetica ]
413 edge [ fontsize=9, dir=back, arrowtail=vee ]
414 gv [ label="Global Variables", shape=box ]
416 tc1 [ label="Test case 1" ];
417 tc2 [ label="Test case 2" ];
418 tcn [ label="Test case n" ];
421 gv -> tc2 [ weight=8 ];
423 tc2 -> tcn [ label="...", dir=none, color=white ];
428 Tests need to run against the background of a known set of
429 objects. This set of objects is called a test fixture. When
430 you are writing tests you will often find that you spend
431 more time writing the code to set up the fixture than you do
432 in actually testing values.
434 ¥Æ¥¹¥È¤ÏÃæ¿È¤Î¤ï¤«¤Ã¤Æ¤¤¤ë¥Ç¡¼¥¿¤Î½¸¤Þ¤ê¤òÁ°Äó¤È¤·¤Æ¼Â¹Ô¤µ¤ì¤ëɬÍפ¬¤¢¤ê¤Þ¤¹¡£
435 ¥Æ¥¹¥È¤ò½ñ¤¤¤Æ¤¤¤ë¤È¡¢
436 ¼ÂºÝ¤Ë¥Æ¥¹¥È¤¹¤ëÃͤò¥»¥Ã¥È¥¢¥Ã¥×¤¹¤ë¥³¡¼¥É¤ò½ñ¤¯Êý¤Ë¡¢
437 ¤è¤ê»þ´Ö¤ò¤«¤±¤Æ¤¤¤ë¤³¤È¤Ëµ¤¤Å¤¯¤³¤È¤¬¤è¤¯¤¢¤ê¤Þ¤¹¡£
442 Î㤨¤ÐÁ°Àá¤Î¥µ¥ó¥×¥ë¥³¡¼¥É¤Ç¤Ï¡¢
443 ¤¤¤¯¤Ä¤«¤ÎÊ£ÁÇ¿ô¤ò³ä¤êÅö¤Æ¤¿¤ê²òÊü¤·¤¿¤ê¤·¤Æ¤¤¤Þ¤¹¡£
447 Often, you will be able to use the same fixture for several
448 different tests. Each case will send slightly different
449 messages or parameters to the fixture and will check for
452 ¿¤¯¤Î¾ì¹ç¡¢¤¤¤¯¤Ä¤«¤Î°Û¤Ê¤Ã¤¿¥Æ¥¹¥È¤Î¤¿¤á¤ËƱ¤¸¥°¥í¡¼¥Ð¥ëÊÑ¿ô¤ò»È¤¦¤³¤È¤¬¤Ç¤¤Þ¤¹¡£
453 ¤½¤ì¤¾¤ì¤Î¥Æ¥¹¥È´Ø¿ô¤ò¼Â¹Ô¤¹¤ëÁ°¤ËÊÑ¿ô¤ò½é´ü²½¤·¡¢
454 ÃͤòÄ´¤Ù¤ë¤³¤È¤Ë¤Ê¤ë¤Ç¤·¤ç¤¦¡£
455 ¤½¤·¤Æ¥Æ¥¹¥È¤¬½ª¤ï¤Ã¤¿¤é¸å»ÏËö¤¹¤ë¤³¤È¤Ë¤Ê¤ê¤Þ¤¹¡£
459 digraph TestFixture {
460 node [ fontsize=9, fontname=Helvetica ]
461 edge [ fontsize=9, dir=back, arrowtail=vee ]
463 gv [ label="Global Variables", shape=box ]
465 su [ label="setUp" ];
466 tc [ label="TestCase" ];
467 td [ label="tearDown" ];
469 gv -> su [ label="initialize" ];
470 gv -> tc [ label="access" ];
471 gv -> td [ label="clean-up" ];
476 When you have a common fixture, here is what you do:
478 ¤â¤·³Æ¥Æ¥¹¥È¤Ë¶¦Ä̤Υ°¥í¡¼¥Ð¥ëÊÑ¿ô¤¬¤¢¤ì¤Ð¡¢
479 ¼¡¤Î¤è¤¦¤Ë¤¹¤ë¤³¤È¤Ç¤·¤ç¤¦¡£
483 For example, to write several test cases, first create a
488 @dontinclude complex/testComplexSetup.c
495 ¥°¥í¡¼¥Ð¥ëÊÑ¿ô¤òÄêµÁ¤·¤Þ¤¹¡£
502 Ê£ÁÇ¿ô¤ò³ä¤êÅö¤Æ¤ë @c setUp ´Ø¿ô¤ò½ñ¤¤Þ¤¹¡£
509 ³ä¤êÅö¤Æ¤¿¥á¥â¥ê¤ò²òÊü¤¹¤ë @c tearDown ´Ø¿ô¤ò½ñ¤¤Þ¤¹¡£
512 @until test_complex_equals
517 ¥Æ¥¹¥È´Ø¿ô¤ò½ñ¤¤Þ¤¹¡£
520 @dontinclude complex/runTestCaseSetup.c
522 @until setUp_test_complex);
523 @until tearDown_test_complex);
527 @c setUp() ¤È @c tearDown() ¤òÅÐÏ¿¤·¤Þ¤¹¡£
528 ¤³¤Î»þ¡¢´Ø¿ô¤Î̾Á°¤¬ @c setUp/tearDown ¤Ç»Ï¤Þ¤Ã¤Æ¤¤¤Ê¤±¤ì¤Ð¤Ê¤ê¤Þ¤»¤ó¡£
535 ¥Æ¥¹¥È¥±¡¼¥¹¤ò¼Â¹Ô¤·¡¢
540 The sample code made in the above is in the directory <code>examples/complex</code>,
541 the files are @c testComplexSetup.c and <code>runTestCaseSetup.c</code>.
543 ¤³¤³¤Þ¤Ç¤Î¥µ¥ó¥×¥ë¥³¡¼¥É¤Ï¡¢@c examples/complex ¥Ç¥£¥ì¥¯¥È¥ê¤Î
544 <code>testComplexSetup.c, runTestCaseSetup.c</code> ¤Ë¤¢¤ê¤Þ¤¹¡£
546 ¥³¥ó¥Ñ¥¤¥ë¤ª¤è¤Ó¼Â¹Ô¤¹¤ë¤Ë¤Ï¡¢¼¡¤Î¤è¤¦¤Ë¤·¤Þ¤¹¡£
550 $ gcc -o runTestCaseSetup runTestCaseSetup.c testComplexSetup.c complex.c -lccunit
559 @section one_time_setUp_tearDown setUp/tearDown of only one time
561 @section one_time_setUp_tearDown °ì²ó¤À¤±¤Î setUp/tearDown
566 Á°¤ÎÀá¤Ç¤Ï¥Æ¥¹¥È¤´¤È¤ËËè²ó½é´ü²½¤ò¹Ô¤Ã¤Æ¤¤¤Þ¤·¤¿¡£
567 °ì²ó¤À¤±½é´ü²½¤ò¹Ô¤Ã¤Æ¡¢
568 Ê£¿ô¤Î¥Æ¥¹¥È¤ò¼Â¹Ô¤·¤¿¤¤¾ì¹ç¤¬¤¢¤ê¤Þ¤¹¡£
569 ¤½¤·¤Æ¥Æ¥¹¥È¤¬Á´¤Æ½ª¤ï¤Ã¤¿¤È¤¤À¤±¸å»ÏËö¤Î¥³¡¼¥É¤ò¼Â¹Ô¤¹¤ë¤è¤¦¤Ê¾ì¹ç¤¬¤¢¤ê¤Þ¤¹¡£
571 ¤½¤Î¤¿¤á¤Ë¤Ï¥Æ¥¹¥È¥±¡¼¥¹¤Ë
572 @c setup_setUp/setup_tearDown ´Ø¿ô¤òÅÐÏ¿¤·¤Þ¤¹¡£
573 ¤¹¤ë¤È¼¡¤Î¤è¤¦¤Ê½ç½ø¤Ç¥Æ¥¹¥È´Ø¿ô¤¬¼Â¹Ô¤µ¤ì¤Þ¤¹¡£
577 digraph TestCaseCallingSequence {
578 node [ fontsize=9, fontname=Helvetica ]
583 setUp2 [ label="setUp" ];
585 setup_setUp -> setUp [ weight=8 ];
586 setup_setUp -> setUp2 [ style=invis ];
587 setUp -> "TestFunc 1" [ weight=8 ];
588 "TestFunc 1" -> tearDown [ weight=8 ];
589 setUp2 -> "TestFunc n" [ weight=8 ];
590 tearDown2 [ label="tearDown" ];
591 "TestFunc n" -> tearDown2;
592 tearDown2 -> setup_tearDown;
601 @section suite ¥¹¡¼¥Ä
605 How do you set up your tests so that you can run them all at once?
606 Once you have several tests, organize them into a suite.
608 Ê£¿ô¤Î¥Æ¥¹¥È¤òÁ´Éô°ìÅ٤˼¹Ԥ¹¤ë¤³¤È¤¬¤Ç¤¤ë¤è¤¦¤Ë½àÈ÷¤¹¤ë¤Ë¤Ï¡¢
609 ¤É¤Î¤è¤¦¤Ë¤·¤¿¤é¤¤¤¤¤Ç¤·¤ç¤¦¤«¡©
610 ¤¤¤¯¤Ä¤«¤Î¥Æ¥¹¥È¤òºî¤Ã¤¿¤é¡¢
611 ¤½¤ì¤é¤ò¥¹¡¼¥Ä (¥¹¥¤¡¼¥È) ¤ËÀ°Íý¤·¤Þ¤¹¡£
615 digraph TestStructure {
616 node [ fontsize=9, fontname=Helvetica ];
617 edge [ dir=back, fontsize=9 ];
618 TestSuite -> TestSuite [ label="1..n" ];
620 TestSuite -> TestCase [ label="1..n" ];
621 TestCase -> setup_setUp [ label="0..1" ];
622 TestCase -> setUp [ label="0..1" ];
624 TestCase -> TestFunc [ label="1..n" ];
625 TestCase -> tearDown [ label="0..1" ];
626 TestCase -> setup_tearDown [ label="0..1" ];
631 CCUnit provides a @link CCUnitTestSuite TestSuite @endlink
632 module that runs any number of TestFuncs together.
633 You saw, above, how to run test suite.
635 CCUnit ¤Ï¤¤¤¯¤Ä¤â¤Î @link CCUnitTestFunc TestFuncs @endlink
637 @link CCUnitTestSuite TestSuite @endlink ¥â¥¸¥å¡¼¥ë¤òÄ󶡤·¤Þ¤¹¡£
638 ¥Æ¥¹¥È¥¹¡¼¥Ä¤ò¼Â¹Ô¤¹¤ëÊýË¡¤Ï¤¹¤Ç¤ËÁ°¤ÎÊý¤Ç¼¨¤·¤Æ¤¢¤ê¤Þ¤¹¡£
642 To create a suite of two or more tests, you do the following:
644 Æó¤Ä°Ê¾å¤Î¥Æ¥¹¥È¤ò´Þ¤à°ì¤Ä¤Î¥¹¡¼¥Ä¤òºî¤ë¤Ë¤Ï¡¢¼¡¤Î¤è¤¦¤Ë¤·¤Þ¤¹¡£
647 @dontinclude complex/runTestSuite.c
650 @until test_complex_div);
654 ¥Æ¥¹¥È¥±¡¼¥¹¤òÆó¤ÄÀ¸À®¤·¡¢¤½¤ì¤¾¤ì¤Ë¥Æ¥¹¥È´Ø¿ô¤òÅÐÏ¿¤·¤Þ¤¹¡£
661 ¥Æ¥¹¥È¥¹¡¼¥Ä¤òÀ¸À®¤·¡¢
662 ¥Æ¥¹¥È¥±¡¼¥¹¤òÅÐÏ¿¤·¤Þ¤¹¡£
669 ¥Æ¥¹¥È¥é¥ó¥Ê¡¼¤òÀ¸À®¤·¥Æ¥¹¥È¤ò¼Â¹Ô¤·¤Þ¤¹¡£
673 The sample code made in the above is in the directory <code>examples/complex</code>,
674 the files are <code>runTestSuite.c</code>, <code>testComplexSetup.c</code>
675 and <code>testComplexArith.c</code>.
677 ¤³¤³¤Þ¤Ç¤Î¥µ¥ó¥×¥ë¥³¡¼¥É¤Ï¡¢<code>examples/complex</code> ¥Ç¥£¥ì¥¯¥È¥ê¤Î
678 <code>runTestSuite.c, testComplexSetup.c, testComplexArith.c</code>
681 ¥³¥ó¥Ñ¥¤¥ë¤ª¤è¤Ó¼Â¹Ô¤¹¤ë¤Ë¤Ï¡¢¼¡¤Î¤è¤¦¤Ë¤·¤Þ¤¹¡£
685 $ gcc -I. -o runTestSuite runTestSuite.c testComplexSetup.c testComplexArith.c complex.c -lccunit
694 @link CCUnitTestSuite TestSuites @endlink don't only have to
695 contain @link CCUnitTestCase TestCases @endlink. They
696 can contain any object that implements the @link CCUnitTest
697 Test @endlink interface. For example, you can create a
698 @link CCUnitTestSuite TestSuite @endlink
700 can create one in mine, and we can run them together by
701 creating a @link CCUnitTestSuite TestSuite @endlink that
704 @link CCUnitTestSuite TestSuites @endlink ¤Ï
705 @link CCUnitTestCase TestCases @endlink
706 ¤ò´Þ¤à¤À¤±¤Ç¤Ï¤¢¤ê¤Þ¤»¤ó¡£
707 @link CCUnitTestSuite TestSuites @endlink ¼«¿È¤ò´Þ¤à¤³¤È¤â¤Ç¤¤Þ¤¹¡£
708 Î㤨¤Ð¡¢¤¢¤Ê¤¿¤Ï¤¢¤Ê¤¿¤Î¥³¡¼¥É¤Ë @link CCUnitTestSuite TestSuite @endlink
711 ¤òºî¤ë¤³¤È¤¬¤Ç¤¤Þ¤¹¡¢
712 ¤½¤·¤Æ»äã¤ÏξÊý¤È¤â¤ò´Þ¤ó¤Ç¤¤¤ë @link CCUnitTestSuite TestSuite @endlink
714 °ì½ï¤Ë¤½¤ì¤¾¤ì¤Î¥¹¡¼¥Ä¤òÆ°¤«¤¹¤³¤È¤¬¤Ç¤¤ë¤Î¤Ç¤¹¡£
718 CCUnitTestSuite* suite;
719 CCUnitTestSuite* suite_a;
720 CCUnitTestSuite* suite_b;
724 suite = ccunit_newTestSuite ("complex all test suite");
725 suite_a = ccunit_newTestSuite ("complex test suite A");
726 suite_b = ccunit_newTestSuite ("complex test suite B");
730 ccunit_addTestSuite (suite, suite_a);
731 ccunit_addTestSuite (suite, suite_b);
735 @section helper_tool Helper Tool
737 @section helper_tool ¥Ø¥ë¥Ñ¡¼¥Ä¡¼¥ë
741 As you might have noticed, implementing the <code>suite
742 ()</code> function of testCase is a repetitive and error
743 prone task. A @ref CreatingTestSuite set of functions and
744 command have been created to automatically implements the
745 <code>suite()</code> function.
748 ¥Æ¥¹¥È¥±¡¼¥¹¤Ë¥Æ¥¹¥È´Ø¿ô¤òÅÐÏ¿¤·¤¿¤ê¡¢
749 ¥Æ¥¹¥È¥¹¡¼¥Ä¤Ë¥Æ¥¹¥È¥±¡¼¥¹¤òÅÐÏ¿¤·¤¿¤ê¤¹¤ëºî¶È¤Ï¡¢
750 È¿ÉüŪ¤Ç´Ö°ã¤¤¤ä¤¹¤¤¤â¤Î¤Ç¤¹¡£
751 Î㤨¤Ð @c testComplexSetup.c ¤Ë¤Ï
752 @c test_complex_to_string() ¤È¤¤¤¦¥Æ¥¹¥È´Ø¿ô¤¬ÄêµÁ¤µ¤ì¤Æ¤¤¤Þ¤¹¤¬¡¢
753 º£¤Þ¤Ç¤ÎÀâÌÀ¤Ç¤Ï̵»ë¤µ¤ì¤Æ¤¤¤Æ¥Æ¥¹¥È¥±¡¼¥¹¤Ë¤ÏÅÐÏ¿¤µ¤ì¤Þ¤»¤ó¤Ç¤·¤¿¡£
754 ¤³¤Î¤è¤¦¤ÊÅÐϿϳ¤ì¤ò¤Ê¤¯¤¹¤¿¤á¤Ë
755 @ref CreatingTestSuite ¤Î´Ø¿ô¤Î½¸¤Þ¤ê¤È¥³¥Þ¥ó¥É¤Ï¡¢
756 ¥Æ¥¹¥È¥±¡¼¥¹¤ä¥Æ¥¹¥È¥¹¡¼¥Ä¤òÅÐÏ¿¤¹¤ë´Ø¿ô¤Î¼ÂÁõ¤ò¡¢
757 ¼«Æ°Åª¤ËºîÀ®¤¹¤ë¤³¤È¤¬¤Ç¤¤Þ¤¹¡£
762 ¥Æ¥¹¥È¥±¡¼¥¹¤ò½ñ¤¯¥Õ¥¡¥¤¥ë¤Ï¼¡¤Î¤è¤¦¤Ëºî¤ê¤Þ¤¹¡£
764 ºÇ½é¤Ë¡¢¥Æ¥¹¥È¥¹¡¼¥Ä¤òÀë¸À¤·¤Þ¤¹¡£
765 ¤³¤ì¤Ï javaDoc ¥¹¥¿¥¤¥ë¤Î¥³¥á¥ó¥ÈÆâ¤Ë¥Æ¥¹¥È¥¹¡¼¥Ä¤Î̾Á°¤òµ½Ò¤·¤Þ¤¹¡£
766 javaDoc¥¹¥¿¥¤¥ë¤Î¥³¥á¥ó¥È¤È¤Ï C ¥¹¥¿¥¤¥ë¤Î¥³¥á¥ó¥È¥Ö¥í¥Ã¥¯¤Î³«»Ï¤¬
767 Æó¤Ä¤Î¥¢¥¹¥¿¥ê¥¹¥¯ <tt>**</tt> ¤Ë¤Ê¤Ã¤Æ¤¤¤ë¤â¤Î¤Ç¤¹¡£
771 //** test suite: complex test suite *\/
777 ¥Æ¥¹¥È¥±¡¼¥¹¤òÄêµÁ¤·¤Þ¤¹¡£
778 ¥Æ¥¹¥È¥±¡¼¥¹¤Ï javaDoc ¥¹¥¿¥¤¥ë¤Î¥³¥á¥ó¥È¤Ë½ñ¤«¤ì¤¿¥Æ¥¹¥È¥±¡¼¥¹¤Î̾Á°¤ÎÀë¸À¤È¡¢
779 ¥Æ¥¹¥È¥±¡¼¥¹¤Î½ªÎ»¤ÎÀë¸À¤Ç°Ï¤Þ¤ì¤¿¥°¥í¡¼¥Ð¥ëÊÑ¿ô¤È´Ø¿ô¤Î½¸¤Þ¤ê¤Ç¤¹¡£
780 ¤Ò¤È¤Ä¤Î¥Õ¥¡¥¤¥ë¤ËÊ£¿ô¤Î¥Æ¥¹¥È¥±¡¼¥¹¤òÄêµÁ¤Ç¤¤Þ¤¹¡£
784 //** test case: complex test case *\/
786 static complex_t* c10_1;
789 void test_complex_new ()
796 //** end test case *\/
797 //** test case: complex arith test case *\/
799 //* end test case *\/
800 //* end test suite *\/
801 //* test suite: ... *\/
803 //* end test suite *\/
808 ¥Æ¥¹¥È´Ø¿ô¤Ï̾Á°¤¬ @c test ¤Ç»Ï¤Þ¤Ã¤Æ¤¤¤Ê¤±¤ì¤Ð¤Ê¤ê¤Þ¤»¤ó¡£
809 ¤Þ¤¿³Æ¥Æ¥¹¥È´Ø¿ô¤ÎÁ°¤Ë¤Ï
810 javaDoc ¥¹¥¿¥¤¥ë¤Î¥³¥á¥ó¥È¤ÎÃæ¤Ë¥Æ¥¹¥È´Ø¿ô¤ÎÀâÌÀ¤ò½ñ¤¯¤³¤È¤¬¤Ç¤¤Þ¤¹¡£
811 ¥³¥á¥ó¥È¤¬½ñ¤«¤ì¤Æ¤¤¤Ê¤±¤ì¤Ð¡¢
812 ¥Æ¥¹¥È´Ø¿ô¤Î̾Á°¤¬´Ø¿ô¤ÎÀâÌÀ¤È¤·¤ÆÅÐÏ¿¤µ¤ì¤Þ¤¹¡£
814 ÆÃÊ̤ʥƥ¹¥È´Ø¿ô¤È¤·¤Æ @c setUp, @c tearDown, @c setup_setUp, @c setup_tearDown
816 ¤½¤Î̾Á°¤«¤é¤ï¤«¤ë¤è¤¦¤Ë¡¢
817 °ÊÁ°¤ËÀâÌÀ¤·¤¿¥Æ¥¹¥È¥±¡¼¥¹¤Îµ¡Ç½¤Î´Ø¿ô¤È¤·¤ÆƯ¤¤Þ¤¹¡£
818 ¤½¤ì¤¾¤ì¤½¤Î¤è¤¦¤Ê̾Á°¤ÇÄêµÁ¤·¤Æ¤¯¤À¤µ¤¤¡£
822 To generate creating suite function code, run
823 <code>ccunit_makeSuite</code> tool.
825 ¥¹¡¼¥ÄºîÀ®´Ø¿ô¤Î¥³¡¼¥É¤òÀ¸À®¤¹¤ë¤Ë¤Ï¡¢
826 <code>ccunit_makeSuite</code>¥Ä¡¼¥ë¤ò¼Â¹Ô¤·¤Þ¤¹¡£
830 The function to make @link CCUnitTestSuite TestSuite
831 @endlink is <code>ccunit_suite</code>.
832 But, it can be changed to another
833 name by the <code>-f</code> option of the
834 <code>ccunit_makeSuite</code> command, too.
837 @link CCUnitTestSuite TestSuite @endlink
839 ¥Ç¥Õ¥©¥ë¥È¤Ç¤Ï <code>ccunit_suite</code> ¤Ç¤¹¡¢
840 ¤·¤«¤· <code>ccunit_makeSuite</code> ¥³¥Þ¥ó¥É¤Î
841 <code>-f</code> ¥ª¥×¥·¥ç¥ó¤ÇÊ̤Î̾Á°¤ËÊѤ¨¤ë¤³¤È¤â¤Ç¤¤Þ¤¹¡£
845 $ ccunit_makeSuite -f suite_test_complex -o suiteTestComplex.c testComplexSetup.c testComplexArith.c
850 ¼«Æ°À¸À®¤·¤¿¥³¡¼¥É¤òÍøÍѤ¹¤ë¤Ë¤Ï¼¡¤Î¤è¤¦¤Ë¤·¤Þ¤¹¡£
853 @dontinclude complex/runTestSuiteAuto.c
860 À¸À®¤·¤¿´Ø¿ô¤Î¥×¥í¥È¥¿¥¤¥×¤òÀë¸À¤·¤Þ¤¹¡£
861 °ú¿ô¤Î <code>char* name</code> ¤ò˺¤ì¤Ê¤¤¤è¤¦¤Ë¤·¤Æ¤¯¤À¤µ¤¤¡£
865 @until suite_test_complex
869 À¸À®¤·¤¿´Ø¿ô¤ò¸Æ¤Ó½Ð¤·¤Æ¥Æ¥¹¥È¥¹¡¼¥Ä¤ò¼è¤ê½Ð¤·¤Þ¤¹¡£
876 ¥Æ¥¹¥È¥é¥ó¥Ê¡¼¤Ç¼Â¹Ô¤·¤Þ¤¹¡£
881 The sample code made in the above is in the directory <code>examples/complex</code>,
882 the files are <code>runTestSuite.c</code>, <code>testComplex.c</code>
883 and <code>testComplexArith.c</code>.
885 ¤³¤³¤Þ¤Ç¤Î¥µ¥ó¥×¥ë¥³¡¼¥É¤Ï¡¢<code>examples/complex</code> ¥Ç¥£¥ì¥¯¥È¥ê¤Î
886 <code>runTestSuiteAuto.c, testComplexSetup.c</code>
889 ¥³¥ó¥Ñ¥¤¥ë¤ª¤è¤Ó¼Â¹Ô¤¹¤ë¤Ë¤Ï¡¢¼¡¤Î¤è¤¦¤Ë¤·¤Þ¤¹¡£
893 $ ccunit_makeSuite -f suite_test_complex -o suiteTestComplex.c testComplexSetup.c testComplexArith.c
894 $ gcc -I. -o runTestSuiteAuto runTestSuiteAuto.c testComplexSetup.c testComplexArith.c suiteTestComplex.c complex.c -lccunit
902 @copydetails CCUnitMakeSuite
905 @section sample_programs Sample Programs
907 @section sample_programs ¥µ¥ó¥×¥ë¥×¥í¥°¥é¥à
911 The sample program made in the above is in the @c examples/complex directory.
913 °Ê¾å¤ÇºîÀ®¤·¤¿¥µ¥ó¥×¥ë¥×¥í¥°¥é¥à¤Ï @c examples/complex ¥Ç¥£¥ì¥¯¥È¥ê¤Ë¤¢¤ê¤Þ¤¹¡£
916 @copydetails examples