1 / 10

WinUnit お気楽お手軽 UnitTest

WinUnit お気楽お手軽 UnitTest. わんくま同盟 MVP for Visual C++ (2004-2008) επιστημη http://blogs.wankuma.com/episteme/ episteme@cppll.jp. επιστημη ちゃ何者ぞ !?. C++ 界ではちった名の知れたソフト屋 わんくま同盟会員番号12番 15年前からの物書き (DDJJ,C-Mag. etc.) C++ 標準化委員会の中のひと Database おんち 組み込み ? Z80/8086 でやりますた わんくま同盟茶藝部顧問 ← いまここ.

luana
Download Presentation

WinUnit お気楽お手軽 UnitTest

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. WinUnit お気楽お手軽 UnitTest わんくま同盟MVP for Visual C++ (2004-2008) επιστημηhttp://blogs.wankuma.com/episteme/episteme@cppll.jp

  2. επιστημη ちゃ何者ぞ!? • C++界ではちった名の知れたソフト屋 • わんくま同盟会員番号12番 • 15年前からの物書き(DDJJ,C-Mag. etc.) • C++標準化委員会の中のひと • Databaseおんち • 組み込み? Z80/8086でやりますた • わんくま同盟茶藝部顧問 ← いまここ

  3. さて今日のお題は WinUnit

  4. WinUnitってば • 数あるUnitTestFrameworkのひとつ • MSDN magazine Feb.2008 に収録 • Windows, Visual C++に限定 • 無償 ─処理系もタダ(VC++Expressおっけ) • JUnit/NUnit並みに簡単 • 小型軽量: header二本/exe一本 だけ • Visual Studio – IDEに統合可

  5. CUnit, CppUnit(C++Test) テスト対象 xUnit header Target header TestCode TargetCode テスト xUnit xUnit library SuiteBuilder + TestRunner compile Test executable link

  6. WinUnit テスト対象 xUnit header Target header TestCode TargetCode テスト xUnit WinUnit executable SuiteBuilder,TestRunner 不要! compile Test DLL link

  7. テスト対象 stack.h #ifndef STACK_H__ #define STACK_H__ #ifdef __cplusplus extern "C" { #endif typedef struct Stack_t* Stack; Stack stack_create(); void stack_delete(Stack stk); void stack_push(Stack stk, int value); int stack_size(Stack stk); void stack_pop(Stack stk); int stack_top(Stack stk); #ifdef __cplusplus } #endif #endif こいつらが「期待通り(仕様通り)  に動いてくれるか」 をテストする。  ↓用意した入力 に対して 期待する結果 が得られる ことを検証する。

  8. テストのかきかた(1)stack_test.cpp #include <WinUnit.h> #include "stack.h" namespace { Stack s; } FIXTURE(stack_fixture); SETUP(stack_fixture){ s = stack_create(); WIN_ASSERT_NOT_NULL(s); } TEARDOWN(stack_fixture){ stack_delete(s); } WinUnit利用に必要なのはこんだけ。 テスト対象。(名前空間を汚染しないよう 匿名namespaceで囲む) 各テストをSETUP(初期化) とTEARDOWN(後始末) で囲む

  9. テストのかきかた(2) stack_test.cpp //---- 初期化 BEGIN_TESTF(01_initialize, stack_fixture) { WIN_ASSERT_ZERO(stack_size(s)); } END_TESTF //---- push BEGIN_TESTF(02_push, stack_fixture) { stack_push(s, 10); WIN_ASSERT_EQUAL( 1, stack_size(s)); WIN_ASSERT_EQUAL(10, stack_top(s)); stack_push(s, 20); WIN_ASSERT_EQUAL( 2, stack_size(s)); WIN_ASSERT_EQUAL(20, stack_top(s)); } END_TESTF 結果は0になるか? 結果が期待値に 等しいか?

  10. DEMO Target • Windows Vista SP1 • (XP also available) • Microsoft Visual Studio 2008 • (VS2005 also available) テスト対象 テスト Test 利用コード Testが成功しない限り Productを作らせない Product

More Related