6. Introduction
今日のお話
Introduction
●
What's
Features
How to use
● Boost.Testの紹介
Conclusion
● Boost.TestというBoostのユニットテ
ストフレームワークを紹介します
12/02/11 Boost.勉強会 #8 大阪 6
7. Introduction
主な対象者
Introduction
●
What's
Features
How to use
● C++でのテストに興味がある人。
Conclusion
● Boost.Testに興味がある人。
● Boost.TestをDISりたい人。
12/02/11 Boost.勉強会 #8 大阪 7
8. Introduction
〜 本日のレシピ 〜
Introduction
What's
Features
How to use ● What's the Boost.Test?
Conclusion
● Boost.Testとは?
● What are the Features?
●
どんな機能がある?
● How to use the Boost.Test
● Boost.Testの使い方/書き方
12/02/11 Boost.勉強会 #8 大阪 8
10. What's the Boost.Test?
Introduction
What's
● Boost.Testとは
Features
How to use
● C++で書かれたC++のテストライブ
Conclusion ラリ
● Boost C++ Librariesに含まれている
●
ドキュメントが長い
12/02/11 Boost.勉強会 #8 大阪 10
11. What's the Boost.Test?
Introduction
What's
● Boost.Testとは
Features
How to use
● Execution Monitor
Conclusion
● Program Execution Monitor
● Minimal Testing Facility
● Unit Test Framework
の4つの機能
12/02/11 Boost.勉強会 #8 大阪 11
12. What's the Boost.Test?
Introduction
What's
● Boost.Testとは
Features
How to use
● Execution Monitor
Conclusion
● Program Execution Monitor
● Minimal Testing Facility
● Unit Test Framework
の4つの機能
12/02/11 Boost.勉強会 #8 大阪 12
13. What's the Boost.Test?
Introduction
What's
● Execution Monitor
Features
How to use
● Boost.Testの基礎
関数の実行を監視して統一的な
Conclusion
●
エラーレポーティングの機能を提供
する。
●
例外
● UNIXのシグナル
● WindowsのSEH
●
面倒なエラー検出を簡単にする。
12/02/11 Boost.勉強会 #8 大阪 13
14. What's the Boost.Test?
Introduction
What's
● Execution Monitor
Features
How to use
● Boost.Testの基礎
関数の実行を監視して統一的な
Conclusion
●
エラーレポーティングの機能を提供
する。
●
例外
● UNIXのシグナル
● WindowsのSEH
●
面倒なエラー検出を簡単にする。
12/02/11 Boost.勉強会 #8 大阪 14
15. What's the Boost.Test?
Introduction
What's
● Execution Monitor
Features
How to use
● Boost.Testの基礎
受け取れる例外は3種類。
Conclusion
●
● C文字列
● std::string
● std::exceptionから派生したクラス
12/02/11 Boost.勉強会 #8 大阪 15
19. What's the Boost.Test?
Introduction
What's
● Boost.Testとは
Features
How to use
● Execution Monitor
Conclusion
● Program Execution Monitor
● Minimal Testing Facility
● Unit Test Framework
の4つの機能
12/02/11 Boost.勉強会 #8 大阪 19
20. What's the Boost.Test?
Introduction
What's
● Program Execution Monitor
Features
How to use
● Execution Monitorで監視された環境
Conclusion でプログラムを実行することで、
エラーレポーティングを簡単にす
る。
● main関数の代わりに提供される
cpp_main関数からプログラムを開始
する。
12/02/11 Boost.勉強会 #8 大阪 20
21. What's the Boost.Test?
Introduction
What's
● Program Execution Monitor
Features
How to use
● cpp_main関数内から例外がなげられ
Conclusion
たり、0以外の値をcpp_mainから返
すとエラーだとみなす。
12/02/11 Boost.勉強会 #8 大阪 21
23. What's the Boost.Test?
#include <iostream>
#include <boost/test/included/prg_exec_monitor.hpp>
int cpp_main(int, char* [])
{
std::cout << "Hello, worldn";
return 0;
}
>./prg_exec_monitor_test.out
Hello, world
no errors detected
12/02/11 Boost.勉強会 #8 大阪 23
24. What's the Boost.Test?
Introduction
What's
● Boost.Testとは
Features
How to use
● Execution Monitor
Conclusion
● Program Execution Monitor
● Minimal Testing Facility
● Unit Test Framework
の4つの機能
12/02/11 Boost.勉強会 #8 大阪 24
25. What's the Boost.Test?
Introduction
What's
● Minimal Testing Facility
テスト作成のための基本的な機能を
Features
●
How to use
Conclusion 提供。
● Testing toolsの一部を使用できる。
● boost/test/minimal.hppをインクルー
ドして、main関数の代わりに
test_main関数からプログラムを開始
する。
12/02/11 Boost.勉強会 #8 大阪 25
26. What's the Boost.Test?
Introduction
What's
● Minimal Testing Facility
テスト作成のための基本的な機能を
Features
●
How to use
Conclusion 提供。
● Testing toolsの一部を使用できる。
● boost/test/minimal.hppをインクルー
ドして、main関数の代わりに
test_main関数からプログラムを開始
する。
12/02/11 Boost.勉強会 #8 大阪 26
27. What's the Boost.Test?
Introduction
What's
● Minimal Testing Facilityで提供されて
Features
いるTesting tools
How to use
Conclusion ● BOOST_CHECK(pred)
– predがfalseならエラーレポートして継続
● BOOST_REQUIRE(pred)
– predがfalseならエラーレポートして中断
● BOOST_ERROR(message)
– エラーレポートして継続
● BOOST_FAIL(message)
– エラーレポートして中断
12/02/11 Boost.勉強会 #8 大阪 27
28. What's the Boost.Test?
Introduction
What's
● Minimal Testing Facility
ヘッダオンリーで使用できるので簡
Features
●
How to use
Conclusion 単。
● 一応Unit Test Framework(UTF)の方もヘッダ
オンリーにすることができる。
しかしUTFの方は長期的に使用する場合は
スタンドアロンライブラリとしてリンクす
ることが推奨される。
12/02/11 Boost.勉強会 #8 大阪 28
29. What's the Boost.Test?
#include <boost/test/minimal.hpp>
int add(int i, int j) { return i*j; }
int test_main(int, char *[]) {
BOOST_CHECK( add(2, 2) == 4 );
BOOST_CHECK( add(2, 3) == 5 );
return 0;
}
>./minimal_test_test.out
minimal_test_test.cpp(6):
test add(2, 3) == 5 failed in function:
'int test_main(int, char**)'
**** 1 error detected
12/02/11 Boost.勉強会 #8 大阪 29
30. What's the Boost.Test?
Introduction
What's
● Boost.Testとは
Features
How to use
● Execution Monitor
Conclusion
● Program Execution Monitor
● Minimal Testing Facility
● Unit Test Framework
の4つの機能
12/02/11 Boost.勉強会 #8 大阪 30
31. What's the Boost.Test?
Introduction
What's
● The Unit Test Framework(UTF)
Features
How to use
● Boost.Testのメイン機能
ヘッダオンリーあるいはスタンドア
Conclusion
●
ロンライブラリとして使用できる。
12/02/11 Boost.勉強会 #8 大阪 31
32. What's the Boost.Test?
Introduction
What's
● Unit Testing Frameworkが満たすべ
Features
き要件
How to use
Conclusion ●
ユニットテストの作業は、プロジェ
クトの実装初期からメンテナンス、
そして後々の改訂にいたるまで、ソ
フトウェア開発のさまざまな段階で
発生する。
● そのためUnit Testing Frameworkに
対して(時に衝突するような)多くの
性質が要求される
12/02/11 Boost.勉強会 #8 大阪 32
40. What's the Features?
Introduction
What's
● Unit Test Frameworkの機能
Features
How to use
● Usage Variant
Conclusion ●
テストランナー
●
モジュール初期化関数
●
テストの作成と組織化
● Fixture
●
テストの出力
●
実行時のテスト設定
● Testing tools
12/02/11 Boost.勉強会 #8 大阪 40
41. What's the Features?
Introduction
What's
● Unit Test Frameworkの機能
Features
How to use
● Usage Variant
Conclusion ●
テストランナー
●
モジュール初期化関数
●
テストの作成と組織化
● Fixture
●
テストの出力
●
実行時のテスト設定
● Testing tools
12/02/11 Boost.勉強会 #8 大阪 41
42. What's the Features?
Introduction
What's
● Usage Variant
Features
How to use
● Testをする状況や環境に合わせて4
Conclusion
種類のUTFの使用法が用意されてい
る。
12/02/11 Boost.勉強会 #8 大阪 42
43. What's the Features?
Introduction
What's
● Usage Variant
Features
How to use
● Static Library Variant
Conclusion
● UTFをスタティックリンクする構成
● Macでは使えない・・・?
http://d.hatena.ne.jp/kei10in/20100623/1277294693
12/02/11 Boost.勉強会 #8 大阪 43
44. What's the Features?
Introduction
What's
● Usage Variant
Features
How to use
● Dynamic Library Variant
Conclusion
● UTFをダイナミックリンクする構成
● #define BOOST_TEST_DYN_LINK
●
(メインになる)ただひとつのソースの
boost/test/unit_test.hppの、そのインクルー
ド前にBOOST_TEST_MAINを定義する。
あるいはBOOST_TEST_MODULEを使用し
てもOK。
12/02/11 Boost.勉強会 #8 大阪 44
45. What's the Features?
Introduction
What's
● Usage Variant
Features
How to use
● Dynamic Library Variant
Conclusion
● Static Library Variantを使用すると
バイナリが大きくなるので、Static
Library Variantを使用した大量のテ
ストのプロジェクトがあるとスト
レージの容量的な問題が起こるか
も。その場合にはDynamic Library
Variantを使用したほう良い。
12/02/11 Boost.勉強会 #8 大阪 45
46. What's the Features?
Introduction
What's
● Usage Variant
Features
How to use
● Single-Header Variant
Conclusion
● UTFをヘッダオンリーにする構成
●
テストモジュールのソースがひとつ
だけの時使える。
●
(コンパイル時間を考えると)長期
的な使用にはスタティックリンクか
ダイナミックリンクを使用するべき
● #include <boost/test/included/unit_test.hpp>
12/02/11 Boost.勉強会 #8 大阪 46
47. What's the Features?
Introduction
What's
● Usage Variant
Features
How to use
● External Test Runner Variant
ビルトインではないテストランナー
Conclusion
●
を使用する構成
●
テストモジュールはダイナミックリ
ンクライブラリとして作成する
● #define BOOST_TEST_DYN_LINK
12/02/11 Boost.勉強会 #8 大阪 47
48. What's the Features?
Introduction
What's
● Unit Test Frameworkの機能
Features
How to use
● Usage Variant
Conclusion ●
テストランナー
●
モジュール初期化関数
●
テストの作成と組織化
● Fixture
●
テストの出力
●
実行時のテスト設定
● Testing tools
12/02/11 Boost.勉強会 #8 大阪 48
49. What's the Features?
テストランナー(Test Runner)
Introduction
●
What's
テストの実行を管理する
Features
●
How to use
Conclusion ●
テストモジュールのエントリポイント
● 実行時パラメータ(コマンドライン引数など)
からUTFを初期化する
● ログとテストのレポート用にOutputを準備
●
などなど・・・
12/02/11 Boost.勉強会 #8 大阪 49
50. What's the Features?
テストランナー(Test Runner)
Introduction
●
What's
ビルトイン以外のテストランナーを
Features
●
How to use
Conclusion 使用することができる。
(先進的なテストランナーはGUIや
テストカバレッジの機能を備えてい
るかも)
(でも見たことない)
●
今日は扱いません。あとよく分かり
ません。
語りえぬものについては、沈黙しなければ
ならない
12/02/11 Boost.勉強会 #8 大阪 50
51. What's the Features?
Introduction
What's
● Unit Test Frameworkの機能
Features
How to use
● Usage Variant
Conclusion ●
テストランナー
●
モジュール初期化関数
●
テストの作成と組織化
● Fixture
●
テストの出力
●
実行時のテスト設定
● Testing tools
12/02/11 Boost.勉強会 #8 大阪 51
52. What's the Features?
モジュール初期化関数
Introduction
●
What's
テストツリーを構築するなど…?
Features
●
How to use
ほとんどビルトインのもので済むの
Conclusion
●
で使わなくても大丈夫
●
今日は扱いません。あとよく分かり
ません。
語りえぬものについては、沈黙しなければ
ならない
12/02/11 Boost.勉強会 #8 大阪 52
53. What's the Features?
Introduction
What's
● Unit Test Frameworkの機能
Features
How to use
● Usage Variant
Conclusion ●
テストランナー
●
モジュール初期化関数
●
テストの作成と組織化
● Fixture
●
テストの出力
●
実行時のテスト設定
● Testing tools
12/02/11 Boost.勉強会 #8 大阪 53
54. What's the Features?
テストの定義と組織化
Introduction
●
What's
Features
How to use
Conclusion ●
テストケースを作成
●
テストケースをテストスイートにグ
ループ化できる
●
テストスイートをさらに大きなテス
トスイートにグループ化できる
12/02/11 Boost.勉強会 #8 大阪 54
56. What's the Features?
テストの定義と組織化
Introduction
●
What's
Features
How to use
● BOOST_AUTO_TEST_CASE(
Conclusion test_case_name
)
●
引数なしテストケースを定義する
BOOST_AUTO_TEST_CASE(test_case_name) {
BOOST_AUTO_TEST_CASE(test_case_name) {
//test body
//test body
}
}
●
手動でテストケースの登録を行う場合は、引
数付きのテストケースを使うことができる。
12/02/11 Boost.勉強会 #8 大阪 56
57. What's the Features?
テストの定義と組織化
Introduction
●
What's
Features
How to use
● BOOST_AUTO_TEST_CASE_TEMPLATE(
Conclusion
test_case_name,
formal_type_parameter_name,
collection_of_types
)
●
テンプレートを使用したテストケー
スを定義する
●
同じ内容で型のみが異なるテストを
書くときに便利
12/02/11 Boost.勉強会 #8 大阪 57
58. What's the Features?
テストの定義と組織化
Introduction
●
What's
Features
How to use
● BOOST_AUTO_TEST_SUITE(
Conclusion test_suite_name
)
●
テストスイートを定義する
BOOST_AUTO_TEST_SUITE(test_suite_name)
BOOST_AUTO_TEST_SUITE(test_suite_name)
// some tests
// some tests
// BOOST_AUTO_TEST_CASE(test1)
// BOOST_AUTO_TEST_CASE(test1)
// { /**/ }
// { /**/ }
BOOST_AUTO_TEST_SUITE_END()
BOOST_AUTO_TEST_SUITE_END()
12/02/11 Boost.勉強会 #8 大阪 58
59. What's the Features?
テストの定義と組織化
Introduction
●
What's
テストケースはテストスイートのなか
Features
●
に複数含めることができる。
How to use
Conclusion
●
テストスイートは入れ子になること
ができる。
12/02/11 Boost.勉強会 #8 大阪 59
61. What's the Boost.Test?
Master Test Suite
Master Test Suite
suite1
suite1
suite2
suite2
test3
test3 test2
test2 test1
test1
12/02/11 Boost.勉強会 #8 大阪 61
62. What's the Features?
Introduction
What's
● Unit Test Frameworkの機能
Features
How to use
● Usage Variant
Conclusion ●
テストランナー
●
モジュール初期化関数
●
テストの作成と組織化
● Fixture
●
テストの出力
●
実行時のテスト設定
● Testing tools
12/02/11 Boost.勉強会 #8 大阪 62
63. What's the Features?
Introduction
What's
● Fixture
テストケースなどで以下の役割を担
Features
●
How to use
Conclusion う
●
テスト開始前に状態を整える
●
テストに関する特定の状態を用意する
●
テスト終了後にクリーンアップをする
12/02/11 Boost.勉強会 #8 大阪 63
64. What's the Features?
Introduction
What's
● Generic Fixture Model
Features
How to use
Conclusion
struct <fixture-name>{
struct <fixture-name>{
<fixture-name>(); // setup function
<fixture-name>(); // setup function
~<fixture-name>(); // teardown function
~<fixture-name>(); // teardown function
};
};
12/02/11 Boost.勉強会 #8 大阪 64
65. What's the Boost.Test?
//Fixtureを使ったテストの例
struct MyFixture {
MyFixture() { i = new int; *i = 0 }
~ MyFixture() { delete i; }
int * i;
};
BOOST_AUTO_TEST_CASE( test_case1 )
{
MyFixture f;
// do something involving f.i
}
12/02/11 Boost.勉強会 #8 大阪 65
66. What's the Boost.Test?
//Fixtureを使ったテストの例
struct MyFixture {
MyFixture() { i = new int; *i = 0 }
~ MyFixture() { delete i; }
int * i;
};
BOOST_AUTO_TEST_CASE( test_case1 )
{
MyFixture f;
// do something involving f.i
}
12/02/11 Boost.勉強会 #8 大阪 66
67. What's the Boost.Test?
struct MyFixture {
MyFixture() { i = new int; *i = 0 }
~ MyFixture() { delete i; }
int * i;
};
BOOST_FIXTURE_TEST_CASE( test_case1, MyFixture )
{
// do something involving i
}
// test_cast1を開始する前にMyFixtureを構築して、
// test_case1が終わるとMyFixtureを破棄する
12/02/11 Boost.勉強会 #8 大阪 67
68. What's the Features?
Introduction
What's
● Fixture
テストケースなどで以下の役割を担
Features
●
How to use
Conclusion う
●
テスト開始前に状態を整える
●
テストに関する特定の状態を用意する
●
テスト終了後にクリーンアップをする
12/02/11 Boost.勉強会 #8 大阪 68
69. What's the Features?
Introduction
What's
● Fixture
Features
How to use
● 3つのレベルでSetupとCleanupを行
Conclusion うことができる
●
テストケース
●
テストスイート
●
グローバル
12/02/11 Boost.勉強会 #8 大阪 69
70. What's the Features?
Introduction
What's
● Fixtureの設定
Features
How to use
● BOOST_FIXTURE_TEST_CASE(
Conclusion
test_case_name,
fixure_name)
● テストケースごとのFixtureを設定
12/02/11 Boost.勉強会 #8 大阪 70
71. What's the Features?
Introduction
What's
● Fixtureの設定
Features
How to use
● BOOST_FIXTURE_TEST_SUITE(
Conclusion
test_suite_name,
fixure_name)
● テストスイートごとのFixtureを設定
●
テストスイート内の各テストケース
が同じFixtureを使用したいときの為
にテストスイートレベルでFixtureを
使用できる。
12/02/11 Boost.勉強会 #8 大阪 71
72. What's the Features?
Introduction
What's
● Fixtureの設定
Features
How to use
● BOOST_GLOBAL_FIXTURE(
Conclusion
fixure_name)
● グローバルなFixtureを設定
●
テストの開始時の初期化を担う
●
テスト用の各ソースファイルに複数
の別のグローバルなFixtureを設定す
ることも可能
12/02/11 Boost.勉強会 #8 大阪 72
73. What's the Features?
Introduction
What's
● Fixtureの設定
Features
How to use
● BOOST_GLOBAL_FIXTURE(
Conclusion
fixure_name)
● グローバルなFixtureを設定
●
テストの開始時の初期化を担う
●
テスト用の各ソースファイルに複数
の別のグローバルなFixtureを設定す
ることも可能
●
でもデストラクト順が厄介・・・?
12/02/11 Boost.勉強会 #8 大阪 73
77. What's the Features?
Introduction
What's
● Unit Test Frameworkの機能
Features
How to use
● Usage Variant
Conclusion ●
テストランナー
●
モジュール初期化関数
●
テストの作成と組織化
● Fixture
●
テストの出力
●
実行時のテスト設定
● Testing tools
12/02/11 Boost.勉強会 #8 大阪 77
78. What's the Features?
テストの出力
Introduction
●
What's
全てのテストで統一的なレポートを
Features
●
How to use
Conclusion ●
エラーについて、ソース上の詳細な
情報を
● テストのエラーの記述(test log)はテ
スト結果の要約(test results report)
とは分離する
●
柔軟な出力内容
●
柔軟な出力の形式
12/02/11 Boost.勉強会 #8 大阪 78
79. What's the Features?
テストの出力
Introduction
●
What's
Features
How to use
● Test Log
Conclusion
● Test Report
● Progress Display
12/02/11 Boost.勉強会 #8 大阪 79
80. What's the Features?
テストの出力
Introduction
●
What's
Features
How to use
● Test Log
Conclusion
● Test Report
● Progress Display
12/02/11 Boost.勉強会 #8 大阪 80
81. What's the Features?
テストの出力
Introduction
●
What's
Features
How to use
● Test Logのレベル
Conclusion ● Success information messages
● Test tree traversal notifications
● General information messages
● Warning messages
● Non fatal error messages
● Uncaught C++ exceptions notifications
● Non-fatal system error
● Fatal system error
12/02/11 Boost.勉強会 #8 大阪 81
82. What's the Features?
テストの出力
Introduction
●
What's
Features
How to use
● Test Logのレベル
各レベルは下のレベルの内容を含む
Conclusion
●
● デフォルトはNon fatal error messages
●
各レベルの詳細は
http://www.boost.org/libs/test/doc/html/utf/user-guide/test-output/test-log.htm
を参照。
12/02/11 Boost.勉強会 #8 大阪 82
83. What's the Features?
テストの出力
Introduction
●
What's
Features
How to use
● operator<<のインターフェースを持
Conclusion たない型がlogに出力されようとした
ときはコンパイルエラーになる。
●
そのコンパイルエラーを避ける場
合、あるいはlogに出力したくない場
合は
BOOST_TEST_DONT_PRINT_LOG_VALUE(
ArgumentType )
を使用する
12/02/11 Boost.勉強会 #8 大阪 83
84. What's the Features?
テストの出力
Introduction
●
What's
Features
How to use BOOST_TEST_MESSAGE(
Conclusion test_message )
● Logにメッセージをさしこむ
● ただし、デフォルトのLogレベルの
設定では出力されない
● LogレベルをGeneral information messages
以上にする
12/02/11 Boost.勉強会 #8 大阪 84
85. What's the Features?
テストの出力
Introduction
●
What's
Features
How to use
● Test Logのレベル
各レベルの詳細は
Conclusion
●
http://www.boost.org/libs/test/doc/html/utf/user-guide/test-output/test-log.html
を参照。
12/02/11 Boost.勉強会 #8 大阪 85
86. What's the Features?
テストの出力
Introduction
●
What's
Features
How to use BOOST_TEST_CHECKPOINT(
Conclusion checkpoint_message)
● Logに名前付きのチェックポイント
をさしこむ
12/02/11 Boost.勉強会 #8 大阪 86
87. What's the Features?
テストの出力
Introduction
●
What's
Features
How to use
● Logの出力フォーマット
Conclusion
● Human Readable
– Microsoft系C++コンパイラのエ
ラー記述に似た形式でLogを出
力
● XML
– XML形式でLogを出力
12/02/11 Boost.勉強会 #8 大阪 87
88. What's the Features?
テストの出力
Introduction
●
What's
Features
How to use
● Logの出力先をコンパイル時に設定
Conclusion
unit_test_log.set_stream(
std::ostream& str );
12/02/11 Boost.勉強会 #8 大阪 88
90. What's the Features?
テストの出力
Introduction
●
What's
Features
How to use
● Log出力のレベルをコンパイル時に
Conclusion 設定する
unit_test_log.set_threshold_level(
boost::unit_test::log_level );
12/02/11 Boost.勉強会 #8 大阪 90
92. What's the Features?
テストの出力
Introduction
●
What's
Features
How to use
● Test Log
Conclusion
● Test Report
● Progress Display
12/02/11 Boost.勉強会 #8 大阪 92
93. What's the Features?
テストの出力
Introduction
●
What's
テストレポートの出力
Features
●
How to use
Conclusion ● Runtime configuration
● Compile time configuration
● Report output stream redirection and access
● Report level configuration
● Predefined report format selection
● Custom report format support
12/02/11 Boost.勉強会 #8 大阪 93
94. What's the Features?
テストの出力
Introduction
●
What's
テストレポートの出力
Features
●
How to use
Conclusion ● Runtime configuration
● Compile time configuration
● Report output stream redirection and access
● Report level configuration
● Predefined report format selection
● Custom report format support
●
ドキュメントに詳細がない・・・?
12/02/11 Boost.勉強会 #8 大阪 94
95. What's the Features?
テストの出力
Introduction
●
What's
Features
How to use
● Test Log
Conclusion
● Test Report
● Progress Display
12/02/11 Boost.勉強会 #8 大阪 95
96. What's the Features?
テストの出力
Introduction
●
What's
Features
How to use
● Progress Display
次に紹介する実行時設定
Conclusion
●
show_progress
を使用する。
> example --show_progress=yes --log_level=nothing
0% 10 20 30 40 50 60 70 80 90 100%
|----|----|----|----|----|----|----|----|----|----|
***************************************************
*** No errors detected
12/02/11 Boost.勉強会 #8 大阪 96
97. What's the Features?
Introduction
What's
● Unit Test Frameworkの機能
Features
How to use
● Usage Variant
Conclusion ●
テストランナー
●
モジュール初期化関数
●
テストの作成と組織化
● Fixture
●
テストの出力
●
実行時のテスト設定
● Testing tools
12/02/11 Boost.勉強会 #8 大阪 97
98. What's the Features?
実行時のテスト設定
Introduction
●
What's
環境変数、あるいは実行時引数でロ
Features
●
グ出力の挙動を設定する
How to use
Conclusion
● auto_start_dbg
● build_info
● catch_system_errors
● detect_memory_leak
● detect_fp_exceptions
12/02/11 Boost.勉強会 #8 大阪 98
99. What's the Features?
実行時のテスト設定
Introduction
●
What's
環境変数、あるいは実行時引数でロ
Features
●
グ出力の挙動を設定する
How to use
Conclusion
● log_format
● log_level
● output_format
● random
● report_format
12/02/11 Boost.勉強会 #8 大阪 99
100. What's the Features?
実行時のテスト設定
Introduction
●
What's
環境変数、あるいは実行時引数でロ
Features
●
グ出力の挙動を設定する
How to use
Conclusion
● report_level
● result_code
● run_test
● show_progress
● use_alt_stack
12/02/11 Boost.勉強会 #8 大阪 100
101. What's the Features?
Introduction
What's
● Unit Test Frameworkの機能
Features
How to use
● Usage Variant
Conclusion ●
テストランナー
●
モジュール初期化関数
●
テストの作成と組織化
● Fixture
●
テストの出力
●
実行時のテスト設定
● Testing tools
12/02/11 Boost.勉強会 #8 大阪 101
102. What's the Features?
Testing tools
Introduction
●
What's
Minimal Testing Facilityの例で使
Features
●
用したBOOST_CHECKなど
How to use
Conclusion
12/02/11 Boost.勉強会 #8 大阪 102
103. What's the Features?
Testing tools
Introduction
●
What's
複数のマクロと関数宣言からなる
Features
●
ツール集。
How to use
Conclusion
●
テストの作成と管理を容易にして、
統一的なエラーレポーティングの仕
組みを提供する。
●
全てのツールは自動的にエラーレ
ポーティングにエラーの位置情報
(ファイル名と行番号)
12/02/11 Boost.勉強会 #8 大阪 103
104. What's the Features?
Testing tools flavors
Introduction
●
What's
全てのテストツールにはflavorsが提
Features
●
供されている
How to use
Conclusion
●
テストツールのアサーションについ
てのレベル的なもの
12/02/11 Boost.勉強会 #8 大阪 104
105. What's the Features?
Testing tools flavors
Introduction
●
What's
WARN
Features
●
How to use
Conclusion ●
警告
●
エラーカウント:そのまま
●
テストの実行:継続
12/02/11 Boost.勉強会 #8 大阪 105
106. What's the Features?
Testing tools flavors
Introduction
●
What's
CHECK
Features
●
How to use
Conclusion ●
エラーチェック
●
エラーカウント:増加
●
テストの実行:継続
12/02/11 Boost.勉強会 #8 大阪 106
107. What's the Features?
Testing tools flavors
Introduction
●
What's
REQUIRE
Features
●
How to use
Conclusion ●
必要条件チェック
●
エラーカウント:増加
●
テストの実行:中断
12/02/11 Boost.勉強会 #8 大阪 107
108. What's the Features?
提供されているTesting tools
Introduction
●
What's
BOOST_<level>
Features
●
How to use
Conclusion
BOOST_CHECK( i == 1 );
BOOST_CHECK( i == 1 );
BOOST_REQUIRE( !str.empty() );
BOOST_REQUIRE( !str.empty() );
Running 1 test case...
testing_tool_test.cpp:10: error in "testing_tool_test":
check i == 1 failed
testing_tool_test.cpp:11: fatal error in "testing_tool_test":
critical check !str.empty() failed
*** 2 failures detected in test suite "Master Test Suite"
12/02/11 Boost.勉強会 #8 大阪 108
109. What's the Features?
提供されているTesting tools
Introduction
●
What's
BOOST_<level>_EQUAL
Features
●
How to use
Conclusion
BOOST_CHECK_EQUAL( i, 1 );
BOOST_CHECK_EQUAL( i, 1 );
BOOST_REQUIRE_EQUAL( str, “STRING” );
BOOST_REQUIRE_EQUAL( str, “STRING” );
Running 1 test case...
testing_tool_test.cpp:10: error in "testing_tool_test":
check i == 1 failed [0 != 1]
testing_tool_test.cpp:11: fatal error in "testing_tool_test":
critical check str == "STRING" failed [ != STRING]
*** 2 failures detected in test suite "Master Test Suite"
12/02/11 Boost.勉強会 #8 大阪 109
110. What's the Features?
提供されているTesting tools
Introduction
●
What's
などなど・・・
Features
●
How to use
Conclusion ●
詳しくはドキュメントに書いてあり
ます。
12/02/11 Boost.勉強会 #8 大阪 110
111. What's the Features?
提供されているTesting tools
Introduction
●
What's
Testing toolsを使うことでテストの
Features
●
意味を分かりやすく書くことがで
How to use
Conclusion
き、さらに統一的なエラーレポー
ティングができるようになる。
12/02/11 Boost.勉強会 #8 大阪 111
112. How to use the Boost.Test
12/02/11 Boost.勉強会 #8 大阪 112
113. How to use the Boost.Test
デモ
Introduction
●
What's
Features
How to use
Conclusion
12/02/11 Boost.勉強会 #8 大阪 113
115. Conclusion
Introduction
What's
● Boost.Testを使うことで、C++のテ
Features
ストを自動的に組織しながらテスト
How to use
Conclusion
を書くことができる。
●
実行時引数を設定することで、柔軟
にテストをすることができる。
● Testing toolsを使うことでテスト内
容を明確にすることができる。
● (Boostに含まれてるので)普段から
Boostを使っている人は導入しやす
い。
12/02/11 Boost.勉強会 #8 大阪 115
116. Conclusion
欠点
Introduction
●
What's
実行時にスキップするテストを選ぶ
Features
●
ことが出来ない
How to use
Conclusion
● Mockの仕組みがない
●
テスト出力のストリームがワイド文
字列対応していない
12/02/11 Boost.勉強会 #8 大阪 116
117. Conclusion
欠点
Introduction
●
What's
実行時にスキップするテストを選ぶ
Features
●
ことが出来ない
How to use
Conclusion
● Mockの仕組みがない
●
テスト出力のストリームがワイド文
字列対応していない
12/02/11 Boost.勉強会 #8 大阪 117
118. Conclusion
Introduction
What's
● Mockの仕組みがない
Features
http://alexott.net/en/cpp/CppTestingIntro.html
How to use
Conclusion ● ここにGoogle MockとBoost.Testを
組み合わせたテストの紹介がありま
す。
12/02/11 Boost.勉強会 #8 大阪 118
119. Conclusion
Introduction
What's
● Mockの仕組みがない
アンドキュメントだがあるらし
Features
●
How to use
Conclusion い・・・?(@cpp_akiraさん情報ありがとうございます)
● see boost/libs/test/example/example/est_example1.cpp
● see boost/libs/test/example/example/est_example2.cpp
12/02/11 Boost.勉強会 #8 大阪 119
120. Conclusion
参考文献/サイト
Introduction
●
What's
Features ● http://www.boost.org/libs/test/doc/html/
How to use ● http://alexott.net/en/cpp/CppTestingIntro.html
Conclusion ● http://www.alittlemadness.com/2009/03/31/c-unit-testing-with-boosttest/
● http://blog.livedoor.jp/naoya_t/archives/51043392.html
12/02/11 Boost.勉強会 #8 大阪 120
121. Conclusion
質問など・・・
Introduction
●
What's
Features
How to use
Conclusion
12/02/11 Boost.勉強会 #8 大阪 121