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 @~japanese Ãͤò¥Á¥§¥Ã¥¯¤·¤¿¤¤¾ì¹ç¤Ï¡¢@~
70 @link CCUNIT_ASSERT() CCUNIT_ASSERT(bool) @endlink
71 @~english and pass a bool that is true if the test succeeds
72 @~japanese ¤ò¸Æ¤Ó½Ð¤·¤Æ¡¢
73 ¤â¤·¥Æ¥¹¥È¤¬À®¸ù¤¹¤ë¤Ê¤é¿¿¤òÊÖ¤¹¤è¤¦¤Ê¿¿µ¶ÃͤòÅϤ·¤Þ¤¹@~
75 @~english ASSERT macro is listed in others as well in
76 @link Assertions Making assertions @endlink.
77 @~japanese ASSERT ´Ø·¸¤Î¥Þ¥¯¥í¤Ï¾¤Ë¤â
78 @link Assertions Making assertions @endlink
79 ¤Ë¥ê¥¹¥È¤·¤Æ¤¢¤ê¤Þ¤¹¡£
85 For example, to test that the sum of two complex number
86 which is the sum of the values of two complex numbers,
89 Î㤨¤Ð¡¢Æó¤Ä¤ÎÊ£ÁÇ¿ô¤Î¹ç·×¤¬¡¢
90 Æó¤Ä¤ÎÊ£ÁÇ¿ô¤ÎÃͤò²Ã»»¤·¤¿ÃͤÈƱ¤¸¤Ç¤¢¤ë¤³¤È¤ò¥Æ¥¹¥È¤¹¤ë¤È¤·¤Þ¤¹¡£
91 ¡Ê¤³¤³¤Ç»ÈÍѤ¹¤ë¥µ¥ó¥×¥ë¥×¥í¥°¥é¥à¤Ï
92 examples/complex ¥Ç¥£¥ì¥¯¥È¥ê¤Ë¤¢¤ê¤Þ¤¹¡£¡Ë
96 This sample program is in the examples/complex directory.
100 void test_complex_add ()
102 complex_t c10_1 = { 10.0, 1.0 };
103 complex_t c1_1 = { 1.0, 1.0 };
105 complex_t c11_2 = { 11.0, 2.0 };
106 CCUNIT_ASSERT (complex_equals (&c11_2, complex_add (&result, &c10_1, &c1_1)));
111 That was a very simple test. Ordinarily, you'll have many
112 little test cases that you'll want to run on the same set of
113 objects. To do this, use a fixture.
115 ¤³¤ì¤ÏÂçÊÑñ½ã¤Ê¥Æ¥¹¥È¤Ç¤¹¡£
116 Ä̾Ʊ¤¸¥Ç¡¼¥¿¤Î¥»¥Ã¥È¤ÇÁö¤é¤»¤ë¤¿¤á¤Ë¡¢
117 ¤¿¤¯¤µ¤ó¤Î¾®¤µ¤Ê¥Æ¥¹¥È¥±¡¼¥¹¤òºî¤é¤Ê¤±¤ì¤Ð¤Ê¤é¤Ê¤¤¤Ç¤·¤ç¤¦¡£
118 ¤½¤³¤Ç¥Õ¥£¥¯¥¹¥Á¥ã¡ÊÈ÷Éʡˤò»È¤¤¤Þ¤¹¡£
122 @section fixture Fixture
124 @section fixture ¥Õ¥£¥¯¥¹¥Á¥ã
128 What if you have two or more tests that operate on the same
129 similar set of objects?
131 ¤â¤·Æó¤Ä°Ê¾å¤Î¥Æ¥¹¥È¤¬¤¢¤ë¤Ê¤é¡¢
132 Ʊ¤¸Îà»÷¤Î¥Ç¡¼¥¿¤Î½¸¤Þ¤ê¤ò»È¤¦¤Î¤Ç¤Ï¤Ê¤¤¤Ç¤·¤ç¤¦¤«¡£
137 node [ fontsize=9, fontname=Helvetica ]
138 edge [ fontsize=9, dir=back, arrowtail=vee ]
139 gv [ label="Data\n(Global variables)", shape=box ]
141 tc1 [ label="Test case 1" ];
142 tcn [ label="Test case n" ];
146 tc1 -> tcn [ style=dotted, arrowtail=none ];
151 Tests need to run against the background of a known set of
152 objects. This set of objects is called a test fixture. When
153 you are writing tests you will often find that you spend
154 more time writing the code to set up the fixture than you do
155 in actually testing values.
157 ¥Æ¥¹¥È¤ÏÃæ¿È¤Î¤ï¤«¤Ã¤Æ¤¤¤ë¥Ç¡¼¥¿¤Î½¸¤Þ¤ê¤òÁ°Äó¤È¤·¤Æ¼Â¹Ô¤µ¤ì¤ëɬÍפ¬¤¢¤ê¤Þ¤¹¡£
158 ¤½¤Î¤è¤¦¤Ê¥Ç¡¼¥¿¤Î½¸¤Þ¤ê¤ò¥Õ¥£¥¯¥¹¥Á¥ã¤È¸Æ¤Ö¤³¤È¤Ë¤·¤Þ¤¹¡£
159 ¥Æ¥¹¥È¤ò½ñ¤¤¤Æ¤¤¤ë¤È¡¢
160 ¼ÂºÝ¤Ë¥Æ¥¹¥È¤¹¤ëÃͤò¥Õ¥£¥¯¥¹¥Á¥ã¤Ë¥»¥Ã¥È¥¢¥Ã¥×¤¹¤ë¥³¡¼¥É¤ò½ñ¤¯Êý¤Ë¡¢
161 ¤è¤ê»þ´Ö¤ò¤«¤±¤Æ¤¤¤ë¤³¤È¤Ëµ¤¤Å¤¯¤³¤È¤¬¤è¤¯¤¢¤ê¤Þ¤¹¡£
165 Often, you will be able to use the same fixture for several
166 different tests. Each case will send slightly different
167 messages or parameters to the fixture and will check for
170 ¿¤¯¤Î¾ì¹ç¡¢¤¤¤¯¤Ä¤«¤Î°Û¤Ê¤Ã¤¿¥Æ¥¹¥È¤Î¤¿¤á¤ËƱ¤¸¥Õ¥£¥¯¥¹¥Á¥ã¤ò»È¤¦¤³¤È¤¬¤Ç¤¤Þ¤¹¡£
171 ¤½¤ì¤¾¤ì¤Î¥Æ¥¹¥È¥±¡¼¥¹¤Ï¾¯¤·°Û¤Ê¤Ã¤¿Ãͤǥե£¥¯¥¹¥Á¥ã¤ò½é´ü²½¤·¡¢
172 °Û¤Ê¤ë·ë²Ì¤òÄ´¤Ù¤ë¤³¤È¤Ë¤Ê¤ë¤Ç¤·¤ç¤¦¡£
173 ¤½¤·¤Æ¥Æ¥¹¥È¤¬½ª¤ï¤Ã¤¿¤é¡¢
174 ¥Õ¥£¥¯¥¹¥Á¥ã¤ò¸å»ÏËö¤¹¤ë¤³¤È¤Ë¤Ê¤ê¤Þ¤¹¡£
175 ¤³¤ì¤é¤Î¥Õ¥£¥¯¥¹¥Á¥ã¤È¡¢
176 ¥Õ¥£¥¯¥¹¥Á¥ã¤ò½é´ü²½¡¦ÍøÍÑ¡¦¸å»ÏËö¤¹¤ë¥Æ¥¹¥È´Ø¿ô¤Î½¸¤Þ¤ê¤ò¡¢
177 ¥Æ¥¹¥È¥Õ¥£¥¯¥¹¥Á¥ã¤È¸Æ¤Ö¤³¤È¤Ë¤·¤Þ¤¹
178 (¤â¤·¤¯¤Ïά¤·¤Æñ¤Ë¥Õ¥£¥¯¥¹¥Á¥ã¤È¸Æ¤Ó¤Þ¤¹¡£)
182 digraph TestFixture {
183 node [ fontsize=9, fontname=Helvetica ]
184 edge [ fontsize=9, dir=back, arrowtail=vee ]
186 subgraph cluster_fixture {
188 label="Test Fixture";
189 gv [ label="Fixture\n(Data)", shape=box ]
191 ssu [ label="setup_setUp" ];
192 su [ label="setUp" ];
193 tc [ label="TestCases" ];
194 td [ label="tearDown" ];
195 std [ label="setup_tearDown" ];
197 gv -> ssu [ label="initialize" ];
198 gv -> su [ label="initialize\neach test" ];
199 gv -> tc [ label="access" ];
200 gv -> td [ label="clean-up\neach test" ];
201 gv -> std [ label="clean-up" ];
207 When you have a common fixture, here is what you do:
209 ¤â¤·³Æ¥Æ¥¹¥È¤Ë¶¦Ä̤¹¤ë¥Ç¡¼¥¿¤¬¤¢¤ì¤Ð¡¢
210 °Ê²¼¤Î¤è¤¦¤Ë¥Æ¥¹¥È¥Õ¥£¥¯¥¹¥Á¥ã¤òºî¤ë¤³¤È¤Ë¤Ê¤ê¤Þ¤¹¡£
215 Create a @link CCUnitTestCase TestCase @endlink object
217 @link CCUnitTestCase TestCase @endlink ¹½Â¤ÂΤ˥á¥â¥ê¤ò³ä¤êÅö¤Æ¤Þ¤¹
218 ¡Ê°Ê¹ß¡¢¹½Â¤ÂΤ˳ä¤êÅö¤Æ¤¿¥á¥â¥ê¤ò¡¢¥ª¥Ö¥¸¥§¥¯¥È¤È¸Æ¤Ö¤³¤È¤Ë¤·¤Þ¤¹¡Ë
222 Add an global variable for each part of the fixture
224 ¥Õ¥£¥¯¥¹¥Á¥ã¤Î¥¹¥³¡¼¥×Æâ¤ËÂç°èÊÑ¿ô¤òÄêµÁ¤·¤Þ¤¹
228 Write @c setup_setUp(), @c setUp() function to initialize the valiables
230 ÊÑ¿ô¤ò½é´ü²½¤¹¤ë @c setup_setUp(), @c setUp() ´Ø¿ô¤ò½ñ¤¤Þ¤¹
234 Write @c tearDown(), @c setup_tearDown() to release any permanent
235 resources you allocated in @c setUp
237 @c setup_setUp(), @c setUp() ¤Ç³ä¤êÅö¤Æ¤¿±Ê³Ū¥ê¥½¡¼¥¹¤ò²òÊü¤¹¤ë¤¿¤á¤Î
238 @c tearDown(), @c setup_tearDown() ´Ø¿ô¤ò½ñ¤¤Þ¤¹
242 Create a @link CCUnitTestFixture TestFixture @endlink object
244 @link CCUnitTestFixture TestFixture @endlink
245 ¹½Â¤ÂΤ˥á¥â¥ê¤ò³ä¤êÅö¤Æ¤Þ¤¹
249 Add @link CCUnitTestCase TestCase @endlink objects to fixture object
251 @link CCUnitTestCase TestCase @endlink ¥ª¥Ö¥¸¥§¥¯¥È¤ò
252 @link CCUnitTestFixture TestFixture @endlink
253 ¥ª¥Ö¥¸¥§¥¯¥È¤ËÅÐÏ¿¤·¤Þ¤¹¡£
259 For example, to write several test cases, first create a
262 Î㤨¤Ð¡¢¤¤¤¯¤Ä¤«¤Î¥Æ¥¹¥È¥±¡¼¥¹¤ò½ñ¤¯¾ì¹ç¡¢
263 ºÇ½é¤Ë¥Õ¥£¥¯¥¹¥Á¥ã¤òºîÀ®¤·¤Þ¤¹¡£
267 //** TEST CASE: complex number test *\/
271 static complex_t* s10_1;
272 static complex_t* s1_1;
273 static complex_t* s11_2;
274 static complex_t* sc;
276 void setup_setUp_complex_test ()
278 sc = complex_new (1, 1);
281 void setup_tearDown_complex_test ()
286 void setUp_complex_test ()
288 s10_1 = complex_new (10, 1);
289 s1_1 = complex_new (1, 1);
290 s11_2 = complex_new (11, 2);
291 complex_add (&sc, &sc, &c1_1);
294 void tearDown_complex_test ()
296 complex_delete (s10_1);
297 complex_delete (s1_1);
298 complex_delete (s11_2);
303 CCUnitTestFixture* fixture;
304 fixture = ccunit_newTestFixture ("complex test",
305 CCUNIT_NEWTESTFUNC(setUp_complex_test),
306 CCUNIT_NEWTESTFUNC(tearDown_complex_test));
307 ccunit_setTestFixturSetup (fixture,
308 CCUNIT_NEWTESTFUNCTION(setup_setUp_complex_test),
309 CCUNIT_NEWTESTFUNCTION(setup_tearDown_complex_test));
313 Once you have the Fixture in place, you can write as complex
314 Test Cases as you'd like.
316 °ìÅÙ·è¤Þ¤Ã¤¿¤È¤³¤í¤Ë¥Õ¥£¥¯¥¹¥Á¥ã¤ò½ñ¤¤¤Æ¤·¤Þ¤¨¤Ð¡¢
317 ¤¢¤Ê¤¿¤¬¹¥¤¤Ê¤è¤¦¤ËÊ£ÁÇ¿ô¤Î¥Æ¥¹¥È¥±¡¼¥¹¤ò½ñ¤¯¤³¤È¤¬¤Ç¤¤Þ¤¹¡£
321 @section test_case Test Case
323 @section test_case ¥Æ¥¹¥È¥±¡¼¥¹
327 How do you write and invoke an individual test case when you
330 ¥Õ¥£¥¯¥¹¥Á¥ã¤ò°ì¤Ä½ñ¤¤¤¿¤È¤·¤Æ¡¢
331 ¤É¤¦¤ä¤Ã¤Æ¸Ä¡¹¤Î¥Æ¥¹¥È¥±¡¼¥¹¤ò½ñ¤¤¤Æ¼Â¹Ô¤¹¤ì¤ÐÎɤ¤¤Ç¤·¤ç¤¦¤«¡£
335 For example, to test the equality of two complex number,
338 Î㤨¤Ð¡¢Æó¤Ä¤ÎÊ£ÁÇ¿ô¤¬Åù¤·¤¤¡Ê¤Þ¤¿¤ÏÅù¤·¤¯¤Ê¤¤¡Ë¤³¤È¤ò¥Æ¥¹¥È¤¹¤ë¤Ë¤Ï¡¢
343 void test_complex_equals ()
345 CCUNIT_ASSERT_TEST_OBJ (s10_1, complex_equals, s10_1, complex_to_string);
346 CCUNIT_ASSERT_TEST_OBJ (s10_1, !complex_equals, s1_1, complex_to_string);
355 ccunit_addNewTestCase (fixture,
356 "test_complex_equals",
357 "complex equals test",
358 test_complex_equals);
362 One may create and run objects for each test case like this:
365 ¥Õ¥£¥¯¥¹¥Á¥ã¤òºîÀ®¤·¤Æ¤½¤ì¤¾¤ì¤Î¥Æ¥¹¥È¥±¡¼¥¹¤ò¼Â¹Ô¤µ¤»¤ë¤³¤È¤¬¤Ç¤¤Þ¤¹¡£
369 CCUnitTestResult* result;
370 result = ccunit_runTestFixture (fixture);
376 Calling sequence of test cases in a fixture is following:
378 ¤Ò¤È¤Ä¤Î¥Õ¥£¥¯¥¹¥Á¥ã¤ÎÃæ¤Î¥Æ¥¹¥È¥±¡¼¥¹¤Î¼Â¹Ô¥·¡¼¥±¥ó¥¹¤Ï¼¡¤Î¤è¤¦¤Ë¤Ê¤ê¤Þ¤¹¡£
382 digraph FixtureCallingSequence {
383 node [ fontsize=9, fontname=Helvetica ]
388 setUp2 [ label="setUp" ];
390 setup_setUp -> setUp [ weight=8 ];
391 setup_setUp -> setUp2 [ style=invis ];
392 setUp -> "TestCase 1" [ weight=8 ];
393 "TestCase 1" -> tearDown [ weight=8 ];
394 setUp2 -> "TestCase n" [ weight=8 ];
395 tearDown2 [ label="tearDown" ];
396 "TestCase n" -> tearDown2;
397 tearDown2 -> setup_tearDown;
403 The sample code made in the above is in the directory <code>examples/complex</code>,
404 the files <code>testComplex.c</code> and <code>runTestFixture.c</code>.
406 ¤³¤³¤Þ¤Ç¤Î¥µ¥ó¥×¥ë¥³¡¼¥É¤Ï¡¢<code>examples/complex</code> ¥Ç¥£¥ì¥¯¥È¥ê¤Î
407 <code>testComplex.c, runTestFixture.c</code> ¤Ë¤¢¤ê¤Þ¤¹¡£
409 ¥³¥ó¥Ñ¥¤¥ë¤ª¤è¤Ó¼Â¹Ô¤¹¤ë¤Ë¤Ï¡¢¼¡¤Î¤è¤¦¤Ë¤·¤Þ¤¹¡£
413 $ gcc -I. -o runTestFixture runTestFixture.c testComplex.c complex.c -lccunit
418 When the test fixture is run, that specific test functions
419 will be run. This is not a useful thing to do, however, as
420 no diagnostics will be displayed. One will normally use a
421 @link ExecutingTest TestRunner @endlink (see below) to
424 ¥Æ¥¹¥È¥Õ¥£¥¯¥¹¥Á¥ã¤¬¼Â¹Ô¤µ¤ì¤ë¤È¡¢
425 »ØÄꤷ¤¿¥Æ¥¹¥È´Ø¿ô¤¬¸Æ¤Ó½Ð¤µ¤ì¤Þ¤¹¡£
426 ¤³¤ì¤Ï¤Þ¤À¤¢¤Þ¤êÊØÍø¤Ç¤Ï¤¢¤ê¤Þ¤»¤ó¡¢
427 ¤Ê¤¼¤Ê¤é¡¢¿ÇÃǤ¬É½¼¨¤µ¤ì¤Ê¤¤¤«¤é¤Ç¤¹¡£
428 Ä̾ï¤Ï @link ExecutingTest TestRunner @endlink
429 (@ref test_runner ¸å½Ò)
434 Once you have several tests, organize them into a suite.
436 °ìÅÙ¤¤¤¯¤Ä¤«¤Î¥Æ¥¹¥È¤òºî¤Ã¤¿¤é¡¢
437 ¤½¤ì¤é¤ò¥¹¡¼¥Ä¤ËÀ°Íý¤·¤Þ¤¹¡£
443 @section suite ¥¹¡¼¥Ä
447 digraph TestStructure {
448 node [ fontsize=9, fontname=Helvetica ];
449 edge [ dir=back, fontsize=9 ];
450 TestSuite -> TestSuite [ label="1..n" ];
452 TestSuite -> TestFixture [ label="1..n" ];
453 TestFixture -> setup_setUp [ label="0..1" ];
454 TestFixture -> setUp [ label="0..1" ];
456 TestFixture -> TestCase [ label="1..n" ];
457 TestFixture -> tearDown [ label="0..1" ];
458 TestFixture -> setup_tearDown [ label="0..1" ];
463 How do you set up your tests so that you can run them all at once?
465 °ìÅ٤˥ƥ¹¥È¤ò¼Â¹Ô¤¹¤ë¤³¤È¤¬¤Ç¤¤ë¤è¤¦¤Ë½àÈ÷¤¹¤ë¤Ë¤Ï¡¢
466 ¤É¤Î¤è¤¦¤Ë¤·¤¿¤é¤¤¤¤¤Ç¤·¤ç¤¦¤«¡©
470 CCUnit provides a @link CCUnitTestSuite TestSuite @endlink
471 module that runs any number of TestCases together.
473 CCUnit ¤Ï¤¤¤¯¤Ä¤â¤Î @link CCUnitTestCase TestCases @endlink
475 @link CCUnitTestSuite TestSuite @endlink ¥â¥¸¥å¡¼¥ë¤òÄ󶡤·¤Þ¤¹¡£
479 You saw, above, how to run test fixture.
481 ¥Æ¥¹¥È¥Õ¥£¥¯¥¹¥Á¥ã¤ò¼Â¹Ô¤¹¤ëÊýË¡¤Ï¾å½Ò¤·¤Þ¤·¤¿¡£
485 To create a suite of two or more tests, you do the following:
487 Æó¤Ä°Ê¾å¤Î¥Æ¥¹¥È¤ò´Þ¤à°ì¤Ä¤Î¥¹¡¼¥Ä¤òºî¤ë¤Ë¤Ï¡¢¼¡¤Î¤è¤¦¤Ë¤·¤Þ¤¹¡£
493 CCUnitTestSuite* suite;
494 CCUnitTestFixture* fixture;
495 CCUnitTestResult* result;
496 suite = ccunit_newTestSuite ("Complex test suite");
497 fixture = ccunit_newTestFixture ("Complex Tests",
498 CCUNIT_NEWTESTFUNC(setUp_complex_test),
499 CCUNIT_NEWTESTFUNC(tearDown_complex_test));
500 ccunit_addNewTestCase (fixture, "test_complex_equals", "complex equals test",
501 test_complex_equals);
502 ccunit_addNewTestCase (fixture, "test_complex_add", "complex add test",
504 ccunit_addNewTestCase (fixture, "test_complex_sub", "complex sub test",
506 ccunit_addTestFixture (suite, fixtuer);
507 result = ccunit_runTestSuite (suite, NULL);
513 @link CCUnitTestSuite TestSuites @endlink don't only have to
514 contain @link CCUnitTestFixture TestFixtures @endlink. They
515 can contain any object that implements the @link CCUnitTest
516 Test @endlink interface. For example, you can create a
517 @link CCUnitTestSuite TestSuite @endlink
518 (<code>complex_add_sub_suite ()</code>) in your code and I
519 can create one in mine
520 (<code>complex_mul_div_suite ()</code>), and we can run them together by
521 creating a @link CCUnitTestSuite TestSuite @endlink that
524 @link CCUnitTestSuite TestSuites @endlink ¤Ï
525 @link CCUnitTestFixture TestFixtures @endlink
526 ¤ò´Þ¤à¤À¤±¤Ç¤Ï¤¢¤ê¤Þ¤»¤ó¡£
527 @link CCUnitTestSuite TestSuites @endlink ¼«¿È¤ò´Þ¤à¤³¤È¤â¤Ç¤¤Þ¤¹¡£
529 ¤½¤ì¤é¤Ï @link CCUnitTest Test @endlink
530 ¥¤¥ó¥¿¥Õ¥§¡¼¥¹¤ò¼ÂÁõ¤¹¤ë¤É¤ó¤Ê¥ª¥Ö¥¸¥§¥¯¥È¤Ç¤â´Þ¤á¤é¤ì¤Þ¤¹¡£
532 Î㤨¤Ð¡¢¤¢¤Ê¤¿¤Ï¤¢¤Ê¤¿¤Î¥³¡¼¥É¤Ë @link CCUnitTestSuite TestSuite @endlink
533 (<code>complex_add_sub_suite ()</code>)
536 (<code>complex_mul_div_suite ()</code>)
537 ¤òºî¤ë¤³¤È¤¬¤Ç¤¤Þ¤¹¡¢
538 ¤½¤·¤Æ»äã¤ÏξÊý¤È¤â¤ò´Þ¤ó¤Ç¤¤¤ë @link CCUnitTestSuite TestSuite @endlink
539 ¤òºî¤Ã¤Æ°ì½ï¤Ë¤½¤ì¤¾¤ì¤Î¥¹¡¼¥Ä¤òÆ°¤«¤¹¤³¤È¤¬¤Ç¤¤ë¤Î¤Ç¤¹¡£
543 CCUnitTestSuite* suite;
544 CCUnitTestResult* result;
545 suite = ccunit_newTestSuite ("Complex add/sub/mul/div test suite");
546 ccunit_addTestSuite (suite, complex_add_sub_suite ());
547 ccunit_addTestSuite (suite, complex_mul_div_suite ());
548 result = ccunit_runTestSuite(suite, NULL);
552 The sample code made in the above is in the directory <code>examples/complex</code>,
553 the files <code>testComplex.c</code>, <code>testComplexMulDiv.c</code>,
554 <code>complexTestSuite.c</code> and <code>runTestSuite.c</code>.
556 ¤³¤³¤Þ¤Ç¤Î¥µ¥ó¥×¥ë¥³¡¼¥É¤Ï¡¢<code>examples/complex</code> ¥Ç¥£¥ì¥¯¥È¥ê¤Î
557 <code>testComplex.c, testComplexMulDiv.c, complexTestSuite.c, runTestSuite.c</code>
560 ¥³¥ó¥Ñ¥¤¥ë¤ª¤è¤Ó¼Â¹Ô¤¹¤ë¤Ë¤Ï¡¢¼¡¤Î¤è¤¦¤Ë¤·¤Þ¤¹¡£
564 $ gcc -I. -o runTestSuite runTestSuite.c testComplex.c testComplexMulDiv.c complexTestSuite.c complex.c -lccunit
569 @section test_runner TestRunner
571 @section test_runner ¥Æ¥¹¥È¥é¥ó¥Ê¡¼
575 How do you run your tests and collect their results?
576 The fixtures store result of own tests into
577 the @link CCUnitTestResult TestResult @endlink.
579 ¤É¤¦¤ä¤Ã¤Æ¥Æ¥¹¥È¤ò¼Â¹Ô¤·¡¢¤½¤Î·ë²Ì¤ò½¸¤á¤¿¤éÎɤ¤¤Ç¤·¤ç¤¦¤«¡£
580 ¥Õ¥£¥¯¥¹¥Á¥ã¤Ï¥Æ¥¹¥È¥±¡¼¥¹¤Î¼Â¹Ô·ë²Ì¤ò
581 @link CCUnitTestResult TestResult @endlink ¤Ë³ÊǼ¤·¤Þ¤¹¡£
586 node [ fontsize=9, fontname=Helvetica ]
588 edge [ fontsize=9, fontname=Courier ]
589 TestFixture -> TestResult [ label="TestFailure", style=dotted, arrowhead=vee ];
591 edge [ fontsize=9, dir=back ]
592 TestFixture -> setUp;
593 TestFixture -> "TestCase 1..n";
594 TestFixture -> tearDown;
595 TestResult -> "TestFailure 0..m";
600 Once you have a test suite, you'll want to run it. %CCUnit
601 provides @link ExecutingTest TestRunner @endlink
602 to define the suite to be run and to display
605 °ì¤Ä¥Æ¥¹¥È¥¹¡¼¥Ä¤ò½ñ¤¤¤¿¤é¡¢
606 ¤½¤ì¤ò¼Â¹Ô¤·¤¿¤¤¤Ç¤·¤ç¤¦¡£
607 CCUnit ¤Ï¥¹¡¼¥Ä¤ò¼Â¹Ô¤¹¤ë¤¿¤á¤ËÄêµÁ¤·¡¢
608 ·ë²Ì¤òɽ¼¨¤¹¤ë¤¿¤á¤Î @link ExecutingTest TestRunner @endlink ¤òÄ󶡤·¤Þ¤¹¡£
612 To use the @link CCUnitTestRunner TestRunner @endlink,
613 include the header files for the tests in runTestRunner.c:
615 @link CCUnitTestRunner TestRunner @endlink ¤ò»ÈÍѤ¹¤ë¤Ë¤Ï¡¢
616 Î㤨¤Ð runTestRunner.c ¤Ç¥Æ¥¹¥È¤Î¤¿¤á¤Î¥Õ¥¡¥¤¥ë¤Î¥Ø¥Ã¥À¤ò¥¤¥ó¥¯¥ë¡¼¥É¤·¤Þ¤¹¡£
620 #include <ccunit/CCUnitTestRunner.h>
621 #include <ccunit/CCUnitTestSuite.h>
626 @link ccunit_runTestRunner()
627 ccunit_runTestRunner (CCUnitTestRunner*, CCUnitTestSuite *) @endlink
628 in the <code>main()</code> function:
630 ¤½¤·¤Æ@link ccunit_runTestRunner()
631 ccunit_runTestRunner (CCUnitTestRunner*, CCUnitTestSuite *) @endlink
632 ¤ò<code>main()</code>´Ø¿ô¤Ç¼Â¹Ô¤·¤Þ¤¹¡£
636 extern CCUnitTestSuite* complex_add_sub_suite ();
637 extern CCUnitTestSuite* complex_mul_div_suite ();
639 int main( int argc, char **argv)
641 CCUnitTestRunner* runner;
642 CCUnitTestSuite* suite;
643 suite = ccunit_newTestSuite ("complex test suite");
644 ccunit_addTestSuite (suite, complex_add_sub_suite ());
645 ccunit_addTestSuite (suite, complex_mul_div_suite ());
646 runner = ccunit_newTestRunner (stdout);
647 return ccunit_runTestRunner (runner, suite);
652 The sample code made in the above is in the directory <code>examples/complex</code>,
653 the files <code>testComplex.c, complexTestSuite.c</code> and <code>runTestRunner.c</code>.
655 ¤³¤³¤Þ¤Ç¤Î¥µ¥ó¥×¥ë¥³¡¼¥É¤Ï¡¢<code>examples/complex</code> ¥Ç¥£¥ì¥¯¥È¥ê¤Î
656 <code>testComplex.c, complexTestSuite.c, runTestRunner.c</code>
659 ¥³¥ó¥Ñ¥¤¥ë¤ª¤è¤Ó¼Â¹Ô¤¹¤ë¤Ë¤Ï¡¢¼¡¤Î¤è¤¦¤Ë¤·¤Þ¤¹¡£
663 $ gcc -I. -o runTestRunner runTestRunner.c testComplex.c testComplexMulDiv.c complexTestSuite.c complex.c -lccunit
672 The @link ExecutingTest TestRunner @endlink will run the tests.
673 If all the tests pass, you'll get an informative message.
674 If any fail, you'll get the following information:
676 @link ExecutingTest TestRunner @endlink ¤Ï¥Æ¥¹¥È¤ò¼Â¹Ô¤·¤Þ¤¹¡£
677 ¤â¤·¤¹¤Ù¤Æ¤Î¥Æ¥¹¥È¤¬¥Ñ¥¹¤¹¤ì¤Ð¡¢¤½¤Î¾ðÊó¤Î¥á¥Ã¥»¡¼¥¸¤¬É½¼¨¤µ¤ì¤Þ¤¹¡£
678 ¾å¤ÎÎã¤Ç¤Ï¡¢ºÇ½é¤Î¡Ö<code>.....</code>¡×¤Ï¼Â¹Ô¤·¤¿¥Æ¥¹¥È¥±¡¼¥¹¤Ç¤¹¡£
679 ¼Â¹Ô¤¹¤ëľÁ°¤Ë¡Ö<code>.</code>¡×¤¬½ÐÎϤµ¤ì¤Þ¤¹¡£
680 Á´¤Æ¤Î¥Æ¥¹¥È¥±¡¼¥¹¤Î¼Â¹Ô¤¬½ªÎ»¤¹¤ë¤È¡¢
681 ¼Â¹Ô¤Ë¤«¤«¤Ã¤¿»þ´Ö¤È¼Â¹Ô¤·¤¿¥Æ¥¹¥È¥±¡¼¥¹¤Î¿ô¤¬É½¼¨¤µ¤ì¤Þ¤¹¡£
683 ¤É¤ì¤«¤¬¼ºÇÔ¤¹¤ì¤Ð¡¢¤½¤ì¤Ë¤Ä¤¤¤Æ°Ê²¼¤Î¤è¤¦¤Ê¾ðÊó¤¬É½¼¨¤µ¤ì¤Þ¤¹¡£
688 The name of the source file that contains the test
690 ¥Æ¥¹¥È¤ò´Þ¤ó¤Ç¤¤¤ë¥½¡¼¥¹¥Õ¥¡¥¤¥ë̾
694 The line number where the failure occurred
700 The name of the test case that failed
702 ¼ºÇÔ¤·¤¿¥Æ¥¹¥È¥±¡¼¥¹¤Î̾Á°
706 All of the text inside the call to
707 <code>CCUNIT_ASSERT ()</code> which detected the failure
709 ¼ºÇÔ¤ò¸¡ÃΤ·¤¿<code>CCUNIT_ASSERT ()</code>¤¬¸Æ¤Ó½Ð¤µ¤ì¤¿»þ¤Î¾ò·ï¤Îʸ»úÎó¡£
716 »î¤·¤Ë @c testComplex.c ¤Î¥Æ¥¹¥È¥±¡¼¥¹¤Ç¤ï¤¶¤È´Ö°ã¤¨¤Æ¤ß¤Þ¤·¤ç¤¦¡£
717 <code>!complex_equals</code> ¤Î <code>!</code> ¤ò¤È¤Ã¤Æ¤ß¤Þ¤¹¡£
721 //* testComplex.c *\/
723 void test_complex_equals ()
725 CCUNIT_ASSERT_TEST_OBJ (s10_1, complex_equals, s10_1, complex_to_string);
726 //*CCUNIT_ASSERT_TEST_OBJ (s10_1, !complex_equals, s1_1, complex_to_string);*\/
727 CCUNIT_ASSERT_TEST_OBJ (s10_1, complex_equals, s1_1, complex_to_string);
732 $ gcc -I. -o runTestRunner runTestRunner.c testComplex.c testComplexMulDiv.c complexTestSuite.c complex.c -lccunit
741 testComplex.c:53: complex equals test:
742 complex_equals (s10_1, s1_1)
749 ¤³¤ÎÎã¤Ç¤Ï¥Æ¥¹¥È¥±¡¼¥¹¤ò 5 ¸Ä¼Â¹Ô¤·¤Æ¡¢
750 ¤Ò¤È¤Ä¤Î¥Æ¥¹¥È¥±¡¼¥¹¤Ç¼ºÇÔ¤·¤Æ¤¤¤ë¤³¤È¤¬¤ï¤«¤ê¤Þ¤¹¡£
751 ºÇ½é¤Î¡Ö<code>.F....</code>¡×¤Ç¤Ï¡¢
752 ¤Ò¤È¤ÄÌܤΥƥ¹¥È¥±¡¼¥¹¤¬¼ºÇÔ¤·¤Æ¤¤¤ë¤³¤È¤ò¤¢¤é¤ï¤·¤Æ¤¤¤Þ¤¹¡£
755 ¼ºÇÔ¤·¤¿¥Õ¥¡¥¤¥ë̾¡¢¹ÔÈֹ桢¥Æ¥¹¥È¥±¡¼¥¹¤Î̾Á° (<code>complex equals test</code>)¡¢
756 ɽÌÀ¤·¤¿¾ò·ï¤Îʸ»úÎó (<code>complex_equals (s10_1, s1_1)</code>)¡¢
757 ´üÂÔ¤·¤¿ÃÍ (<code>10+1i</code>)¡¢
758 ¼ÂºÝ¤ÎÃÍ (<code>1+1i</code>)
763 @section helper_macros Helper Tool
765 @section helper_macros ¥Ø¥ë¥Ñ¡¼¥Ä¡¼¥ë
769 As you might have noticed, implementing the <code>suite
770 ()</code> function of fixture is a repetitive and error
771 prone task. A @ref CreatingTestSuite set of functions and
772 command have been created to automatically implements the
773 <code>suite()</code> function.
775 ¤ªµ¤¤Å¤¤Î¤è¤¦¤Ë¡¢¥Õ¥£¥¯¥¹¥Á¥ã¤Î <code>suite ()</code>´Ø¿ô¤ò¼ÂÁõ¤¹¤ë¤Î¤Ï¡¢
776 È¿ÉüŪ¤Ç´Ö°ã¤¤¤ä¤¹¤¤ºî¶È¤Ç¤¹¡£
777 @ref CreatingTestSuite ¤Î´Ø¿ô¤Î½¸¤Þ¤ê¤È¥³¥Þ¥ó¥É¤Ï<code>suite ()</code>
778 ´Ø¿ô¤Î¼ÂÁõ¤ò¼«Æ°Åª¤ËºîÀ®¤¹¤ë¤³¤È¤¬¤Ç¤¤Þ¤¹¡£
781 @dontinclude complex/testComplex.c
784 The following code is a rewrite of ComplexTest using those command:
786 °Ê²¼¤Î¥³¡¼¥É¤Ï¤½¤ì¤é¤Î¥³¥Þ¥ó¥É¤¬»È¤¦¤è¤¦¤Ë testComplex.c ¤ò½ñ´¹¤¨¤¿¤â¤Î¤Ç¤¹¡£
790 First, you declare the fixture, passing the test fixture
791 name to the javaDoc style comment, which consist of a
792 C-style comment block starting with two <tt>*</tt>'s:
794 ºÇ½é¤Ë¡¢¥Õ¥£¥¯¥¹¥Á¥ã¤òÀë¸À¤·¤Þ¤¹¡£
795 ¤³¤ì¤ÏjavaDoc¥¹¥¿¥¤¥ë¤Î¥³¥á¥ó¥ÈÆâ¤Ë¥Õ¥£¥¯¥¹¥Á¥ã¤Î̾Á°¤òµ½Ò¤·¤Þ¤¹¡£
796 javaDoc¥¹¥¿¥¤¥ë¤Î¥³¥á¥ó¥È¤È¤Ï C ¥¹¥¿¥¤¥ë¤Î¥³¥á¥ó¥È¥Ö¥í¥Ã¥¯¤Î³«»Ï¤¬
797 Æó¤Ä¤Î¥¢¥¹¥¿¥ê¥¹¥¯ <tt>**</tt> ¤Ë¤Ê¤Ã¤Æ¤¤¤ë¤â¤Î¤Ç¤¹¡£
801 #include <ccunit/CCUnitAssert.h>
803 //** test case: complex number test *\/
807 The function to make @link CCUnitTestSuite TestSuite
808 @endlink is <code>ccunit_suite</code>.
809 But, it can be changed to another
810 name by the <code>-f</code> option of the
811 <code>ccunit_makeSuite</code> command, too.
812 Then, you define each test case of the fixture with prefix
813 <code>test</code>, <code>setUp</code>,
814 <code>tearDown</code>:
816 @link CCUnitTestSuite TestSuite @endlink
817 ¤òºîÀ®¤¹¤ë´Ø¿ô¤Ï <code>ccunit_suite</code> ¤Ç¤¹¡¢
818 ¤·¤«¤· <code>ccunit_makeSuite</code> ¥³¥Þ¥ó¥É¤Î
819 <code>-f</code> ¥ª¥×¥·¥ç¥ó¤ÇÊ̤Î̾Á°¤ËÊѤ¨¤ë¤³¤È¤â¤Ç¤¤Þ¤¹¡£
820 ¤½¤·¤Æ¡¢¥Õ¥£¥¯¥¹¥Á¥ã¤Î¥Æ¥¹¥È¥±¡¼¥¹¤Ë¤Ï¤½¤ì¤¾¤ì̾Á°¤ÎÀèƬ¤Ë¡¢
821 <code>test</code>, <code>setUp</code>,
822 <code>tearDown</code> ¤ò¤Ä¤±¤Æ¤¯¤À¤µ¤¤¡£
828 static complex_t* s10_1;
829 static complex_t* s1_1;
830 static complex_t* s11_2;
831 static complex_t* sc;
833 void setup_setUp_complex_test ()
835 sc = complex_new (1, 1);
838 void setup_tearDown_complex_test ()
843 void setUp_complex_test ()
845 s10_1 = complex_new (10, 1);
846 s1_1 = complex_new (1, 1);
847 s11_2 = complex_new (11, 2);
850 void tearDown_complex_test ()
852 complex_delete (s10_1);
853 complex_delete (s1_1);
854 complex_delete (s11_2);
858 void test_complex_equals ()
860 CCUNIT_ASSERT_TEST_OBJ (s10_1, complex_equals, s10_1, complex_to_string);
861 CCUNIT_ASSERT_TEST_OBJ (s10_1, !complex_equals, s1_1, complex_to_string);
865 void test_complex_add ()
867 complex_t c10_1 = { 10.0, 1.0 };
868 complex_t c1_1 = { 1.0, 1.0 };
870 complex_t c11_2 = { 11.0, 2.0 };
871 CCUNIT_ASSERT (complex_equals (&c11_2, complex_add (&result, &c10_1, &c1_1)));
875 void test_complex_sub ()
877 complex_t c9_0 = { 9, 0 };
879 CCUNIT_ASSERT_TEST_OBJ (&c9_0, complex_equals,
880 complex_sub (&result, s10_1, s1_1),
886 Finally, you end the fixture declaration:
888 ºÇ¸å¤Ë¡¢¥Õ¥£¥¯¥¹¥Á¥ã¤Î½ª¤ê¤òÀë¸À¤·¤Þ¤¹¡£
892 //** end test case *\/
897 ¤Ò¤È¤Ä¤Î¥Õ¥¡¥¤¥ë¤ÎÃæ¤ËÊ£¿ô¤Î¥Õ¥£¥¯¥¹¥Á¥ã¤òÄêµÁ¤¹¤ë¤³¤È¤â¤Ç¤¤Þ¤¹¡£
898 ¤½¤Î¾ì¹ç¤Ï¡¢¥Õ¥£¥¯¥¹¥Á¥ã¤Î½ª¤ï¤ê¤ÎÀë¸À¤Î¸å¤Ë³¤±¤Æ¥Õ¥£¥¯¥¹¥Á¥ã¤òÄêµÁ¤·¤Æ¤¯¤À¤µ¤¤¡£
902 To generate creating suite function code, run
903 <code>ccunit_makeSuite</code> tool.
905 ¥¹¡¼¥ÄºîÀ®´Ø¿ô¤Î¥³¡¼¥É¤òÀ¸À®¤¹¤ë¤Ë¤Ï¡¢
906 <code>ccunit_makeSuite</code>¥Ä¡¼¥ë¤ò¼Â¹Ô¤·¤Þ¤¹¡£
910 $ ccunit_makeSuite -f complex_suite -o suiteComplex.c testComplex.c
913 #include <ccunit/CCUnitTestSuite.h>
914 #include <ccunit/CCUnitTestFixture.h>
915 #include <ccunit/CCUnitTestCase.h>
917 //* test fixture: complex number test *\/
918 //* setUp_complex_test *\/
919 extern void setUp_complex_test ();
920 //* tearDown_complex_test *\/
921 extern void tearDown_complex_test ();
922 //* test_complex_equals *\/
923 extern void test_complex_equals ();
924 //* test_complex_add *\/
925 extern void test_complex_add ();
926 //* test_complex_sub *\/
927 extern void test_complex_sub ();
929 static CCUnitTestFunc fx_001_cases[] = {
931 "test_complex_equals",
950 static CCUnitTestFixtureDfn fx_001 = {
951 { ccunitTypeFixture },
952 "complex number test",
954 "setup_setUp_complex_test",
955 "setup_setUp_complex_test",
956 setup_setUp_complex_test
959 "setup_tearDown_complex_test",
960 "setup_tearDown_complex_test",
961 setup_tearDown_complex_test
964 "setUp_complex_test",
965 "setUp_complex_test",
969 "tearDown_complex_test",
970 "tearDown_complex_test",
971 tearDown_complex_test
976 static CCUnitTestDfn* suite_001_test[] = {
981 static CCUnitTestSuiteDfn suite_001 = {
988 CCUnitTestSuite* complex_suite (const char* name)
990 if (!suite_001.name[0])
991 suite_001.name = name;
992 return ccunit_newTestSuiteFromDfn (&suite_001);
998 Fixtures can be packaged into test suite.
999 You declare the suite before fixtures.
1001 ¤Ê¤ª¡¢¤¤¤¯¤Ä¤«¤Î¥Õ¥£¥¯¥¹¥Á¥ã¤ò¥Æ¥¹¥È¥¹¡¼¥Ä¤Ë¤Þ¤È¤á¤ë¤³¤È¤â¤Ç¤¤Þ¤¹¡£
1002 ¤½¤Î¤¿¤á¤Ë¤Ï¡¢¥Õ¥£¥¯¥¹¥Á¥ã¤ÎÄêµÁ¤ÎÁ°¤Ë¥Æ¥¹¥È¥¹¡¼¥Ä¤òÀë¸À¤·¤Þ¤¹¡£
1006 //** test suite: complex number test suite *\/
1007 //** test case: complex number equality test *\/
1009 //** test case: complex number compute test *\/
1013 @copydetails CCUnitMakeSuite
1016 @section post_build_check Post-build check
1018 @section post_build_check ¥Ó¥ë¥É¸å¤Î¥Á¥§¥Ã¥¯
1022 Now that we have our unit tests running, how about
1023 integrating unit testing to our build process ?
1025 ¤µ¤¢¥æ¥Ë¥Ã¥È¥Æ¥¹¥È¤ò¼Â¹Ô¤¹¤ë½àÈ÷¤¬¤Ç¤¤Þ¤·¤¿¡£
1026 ¤Ç¤Ï¥Ó¥ë¥É¥×¥í¥»¥¹¤Ë¥æ¥Ë¥Ã¥È¥Æ¥¹¥È¤òÅý¹ç¤¹¤ë¤Ë¤Ï¤É¤¦¤·¤¿¤é¤¤¤¤¤Ç¤·¤ç¤¦¡£
1030 To do that, the application must returns a value different than 0 to indicate that
1033 ¤½¤¦¤¹¤ë¤Ë¤Ï¡¢¥¢¥×¥ê¥±¡¼¥·¥ç¥ó¤Ï¡¢¥¨¥é¡¼¤¬È¯À¸¤·¤¿¤³¤È¤ò¼¨¤¹
1034 0 °Ê³°¤ÎÃͤòÊÖ¤µ¤Ê¤±¤ì¤Ð¤Ê¤ê¤Þ¤»¤ó¡£
1038 @link ccunit_runTestRunner() ccunit_runTestRunner() @endlink returns
1039 a integer indicating if the run was successful.
1041 @link ccunit_runTestRunner() ccunit_runTestRunner() @endlink
1042 ¤Ï¡¢¼Â¹Ô¤¬À®¸ù¤·¤¿¤«¤É¤¦¤«¤ò¼¨¤¹À°¿ô¤òÊÖ¤·¤Þ¤¹¡£
1046 Updating our main programm, we obtains:
1048 ¼¡¤Î¤è¤¦¤Ë¥á¥¤¥ó¥×¥í¥°¥é¥à¤ò¹¹¿·¤·¤Þ¤¹¡£
1052 #include <ccunit/CCUnitTestRunner.h>
1054 extern CCUnitTestSuite* complex_suite(const char* name);
1056 int main (int argc, char** argv)
1058 CCUnitTestRunner* runner;
1059 CCUnitTestSuite* suite;
1061 runner = ccunit_newTestRunner (stdout);
1062 suite = complex_suite ("complex test suite");
1063 wasSucessful = ccunit_runTestRunner (runner, suite);
1064 return wasSucessful;
1069 Now, you need to run your application after compilation.
1071 ¤½¤ì¤Ç¤Ï¥¢¥×¥ê¥±¡¼¥·¥ç¥ó¤ò¥³¥ó¥Ñ¥¤¥ë¤·¤¿¸å¤Ë¼Â¹Ô¤·¤Æ¤ß¤Þ¤·¤ç¤¦¡£
1075 $ gcc -I. -o runTest runTest.c testComplex.c suiteComplex.c complex.c -lccunit
1084 $ ccunit_makeSuite -f complex_suite -o suiteComplex.c testComplex.c testComplexMulDiv.c
1085 $ gcc -I. -o runTest runTest.c testComplex.c testComplexMulDiv.c suiteComplex.c complex.c -lccunit
1094 The sample program made in the above is in the @c examples/complex directory.
1096 °Ê¾å¤ÇºîÀ®¤·¤¿¥µ¥ó¥×¥ë¥×¥í¥°¥é¥à¤Ï @c examples/complex ¥Ç¥£¥ì¥¯¥È¥ê¤Ë¤¢¤ê¤Þ¤¹¡£
1099 - complex - @~english some complex number library test cases
1100 @~japanese Ê£ÁÇ¿ô¤ò·×»»¤¹¤ë¥é¥¤¥Ö¥é¥ê¤È¤½¤Î¥Æ¥¹¥È¥±¡¼¥¹¤Î¥µ¥ó¥×¥ë¤Ç¤¹¡£@~
1101 - libcomplex.a - complex number library
1104 - runTestFixture @~japanese - ¤â¤Ã¤È¤âñ½ã¤Ê¥Æ¥¹¥È¥±¡¼¥¹¤ò¼Â¹Ô¤¹¤ë¥µ¥ó¥×¥ë¤Ç¤¹¡£@~
1105 - runTestFixture.c - main program
1106 - testComplex.c - test cases
1107 - runTestSuite @~japanese - ¥Æ¥¹¥È¥¹¡¼¥Ä¤Î¥µ¥ó¥×¥ë¤Ç¤¹¡£@~
1108 - runTestSuite.c - main program
1109 - testComplex.c - test cases
1110 - testComplexMulDiv.c - test cases
1111 - complexTestSuite.c - create test suite function
1112 - runTestRunner @~japanese - ¥Æ¥¹¥È¥¹¡¼¥Ä¤ò¥Æ¥¹¥È¥é¥ó¥Ê¡¼¤Ç¼Â¹Ô¤¹¤ë¥µ¥ó¥×¥ë¤Ç¤¹¡£@~
1113 - runTestRunner.c - main program
1114 - testComplex.c - test cases
1115 - testComplexMulDiv.c - test cases
1116 - complexTestSuite.c - create test suite function
1117 - runTest @~japanese - ¥Æ¥¹¥È¥¹¡¼¥Ä¤ò¼«Æ°À¸À®¤¹¤ë¥µ¥ó¥×¥ë¤Ç¤¹¡£@~
1118 - runTest.c - main program
1119 - testComplex.c - test cases
1120 - suiteComplex.c - auto generated test suite from testComplex.c