
| #ifdef _DEBUG //包括测试头文件 #include <msVC6/testrunner/TestRunner.h> #include <cppunit/extensions/TestFactoryReGIStry.h> static AFX_EXTENSION_MODULE extTestRunner; #endif //以下为测试代码,此部分测试不会出现在发布版中 #ifdef _DEBUG TestRunner runner; runner.addTest ( CppUnit::TestFactoryRegistry::getRegistry().makeTest() ); runner.run (); #endif |
| TESTS = check_xxxx noinst_PROGRAMS=check_xxxx frame_path=xx/check-0.8.0 xxxx_docs =\ srcfilelist_1\ srcfilelist_2\ .......\ ..... xxxx_SOURCES=\ srcfilelist_1\ srcfilelist_2\ ....... EXTRA_DIST = $(xxxx_docs) INCLUDES = -I$(frame_path)/src -I$(other_path)/include LDADD= \$(frame_path)/src/libcheck.a CLEANFILES=*.*~ |
| #include <stdlib.h> #include <check.h> #include "money.h" /*建立必要的测试变量,Money为money.h中定义的结构struct money*/ Money *five_dollars; /*单元测试初始化函数*/ void setup (void) { five_dollars = money_create(5, "USD"); } /*单元测试结束函数*/ void teardown (void) { money_free (five_dollars); } /*单元测试用例,用例名为test_create*/ /*test functions: money_amout()*/ START_TEST(test_create) { /*功能性测试,属黑盒测试*/ /*normal test*/ fail_unless (money_amount(five_dollars) = = 5, "Amount not set correctly on creation"); fail_unless (strcmp(money_currency(five_dollars),"USD") = = 0, "Currency not set correctly on creation"); /*条件及错误路径测试,属白盒测试*/ /*extra test*/ } END_TEST /*单元测试用例,用例名为test_net_create*/ START_TEST(test_neg_create) { Money *m = money_create(-1, "USD"); fail_unless (m = = NULL, "NULL should be returned on attempt to create with a negative amount"); } END_TEST /*单元测试用例,用例名为test_net_create*/ START_TEST(test_zero_create) { Money *m = money_create(0, "USD"); fail_unless (money_amount(m) = = 0, "Zero is a valid amount of money"); } END_TEST /*单元测试组装,将所有单元测试组装到一个“箱子”里面,“箱子”名为Money*/ Suite *money_suite (void) { Suite *s = suite_create("Money"); /*测试用例分组*/ TCase *tc_core = tcase_create("Core"); TCase *tc_limits = tcase_create("Limits"); /*将分组加入“箱子” suite_add_tcase (s, tc_core); suite_add_tcase (s, tc_limits); /*分别将不同用例加入分组*/ tcase_add_test (tc_core, test_create); tcase_add_checked_fixture (tc_core, setup, teardown); /*此用例注册初始化和结束函数*/ /*以下用例将不注册初始化和结束函数*/ tcase_add_test (tc_limits, test_neg_create); tcase_add_test (tc_limits, test_zero_create); return s; } /*执行测试用例*/ int main (void) { int nf; Suite *s = money_suite(); SRunner *sr = srunner_create(s); srunner_run_all (sr, CK_NORMAL); nf = srunner_ntests_failed(sr); srunner_free(sr); suite_free(s); return (nf == 0) ? EXIT_SUCCESS : EXIT_FAILURE; } |
| 关于我们 | 联系我们 | 广告服务 | 工作机会 | 版权声明 | 欢迎投稿 | 网站地图 |
| Copyright © 2000-2008 , www.21tx.com , All Rights Reserved . |
| © 晨新科技 版权所有 Created by TXSite.net |