Boost.Testの紹介




           @hotwatermorning

12/02/11       Boost.勉強会 #8 大阪   1
自己紹介




                  ●   @hotwatermorning
                  ●
                      札幌から来ました




12/02/11   Boost.勉強会 #8 大阪               2
自己紹介




                  ●   @hotwatermorning
                  ●
                      札幌から来ました
                  ●
                      今季は水道が2回凍結
                      しました。



12/02/11   Boost.勉強会 #8 大阪           3
自己紹介
 ●
     2011年は、
               <= C++の同人誌書いたり、




Boost.勉強会 #6 @札幌を
開催したりしました =>
                           http://www.flickr.com/photos/miio119/6318681082/

 12/02/11      Boost.勉強会 #8 大阪                                       4
Introduction




12/02/11     Boost.勉強会 #8 大阪   5
Introduction
                    今日のお話
Introduction
                ●
  What's
 Features
How to use
                ●   Boost.Testの紹介
Conclusion
                ●   Boost.TestというBoostのユニットテ
                    ストフレームワークを紹介します




               12/02/11         Boost.勉強会 #8 大阪   6
Introduction
                    主な対象者
Introduction
                ●
  What's
 Features
How to use
                ●   C++でのテストに興味がある人。
Conclusion
                ●   Boost.Testに興味がある人。
                ●   Boost.TestをDISりたい人。




               12/02/11         Boost.勉強会 #8 大阪   7
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
What's the Boost.Test?




12/02/11          Boost.勉強会 #8 大阪   9
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
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
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
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
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
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
What's the Boost.Test?
#include <stdexcept>
#include <iostream>
#include <boost/test/execution_monitor.hpp>
#include <boost/test/utils/basic_cstring/io.hpp>
int foo() {
    throw std::runtime_error("some error has occured");
    return 0;
}
int main() {
    boost::execution_monitor mon;
    try {
        return mon.execute(foo);
ᅠ ᅠ ᅠ } catch(boost::execution_exception const &e) {
ᅠ ᅠ ᅠ ᅠ std::cout << e.what() << std::endl;
ᅠ ᅠ }
}
 12/02/11                    Boost.勉強会 #8 大阪              16
What's the Boost.Test?
Introduction
  What's
                ●   Execution Monitor
 Features
How to use
                ●   Boost.Testの基礎
                    受け取れる例外は、
Conclusion
                ●

                    ●     C文字列
                    ●     std::string
                    ●     std::exceptionから派生したクラス
                          の3種類。
                    ●     これ以外の例外をExecution Monitorで捕捉
                          したい場合はexecution_monitorの
                          register_exception_translatorを使用する。
               12/02/11                 Boost.勉強会 #8 大阪         17
What's the Boost.Test?
struct my_error {
    my_error(int code) : code_(code) {}
    int      code_;
};
void trns_my_error(my_error const& e) {
    throw std::domain_error(e.code_ == 0 ? "code is zero" : "otherwise");
}
int main() {
    boost::execution_monitor mon;
    mon.register_exception_translator<my_error>(&trns_my_error);
    try {
        return mon.execute(bar); //bar may throw my_error.
      } catch(boost::execution_exception const &e) {
        std::cout << e.what() << std::endl;
    }
}

 12/02/11                    Boost.勉強会 #8 大阪                           18
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
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
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
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;
}




12/02/11             Boost.勉強会 #8 大阪              22
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
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
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
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
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
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
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
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
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
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
Requirements of UTF
●
    シンプルで、使い始めの人にも分かりやすくユニットテ
    ストモジュールが書けるべき

●
    上級者が自明でないようなテストをすることも可能であ
    るべき

●
    テストモジュールはたくさんの小さなテストケースを持
    つことができ、開発者がそれをテストスイートにグルー
    プ化することができるべき

●
    開発初期にはユーザーは詳細で説明的なエラーメッセー
    ジを見たい。しかし回帰テスト中にはどのテストが失敗
    したかだけを知りたい。
12/02/11         Boost.勉強会 #8 大阪   33
Requirements of UTF(Cont'd)
●
    小さいテストモジュールの実行時間>コンパイル時間で
    あるべき。実行に1秒しかかからないテストのコンパイ
    ルに1分も待ちたくはない。

●
    長く複雑なテストではユーザーはテストの進捗を見られ
    るようにしたい。

●
    簡単なテストは外部ライブラリを必要とするべきではな
    い。

●
    長期的な使用のためにユニットテストフレームワークは
    スタンドアロンなライブラリとしてビルドできるべき。

12/02/11           Boost.勉強会 #8 大阪       34
What's the Boost.Test?
Introduction
  What's
                ●   UTFの設計はこれらをベースにして
 Features
                    いる。そしてUTFは多岐に渡る機能
                    を提供する
How to use
Conclusion
                    ●     さまざまなTesting toolsを使用することで簡
                          単にテストを書くことができる。
                    ●
                          一つのテストツリーの中にテストケースを組
                          織化できる。
                    ●
                          面倒なエラー検出とレポーティングの義務
                          とフレームワークの実行時パラメータ処理
                          からあなたを解放する。
                          などなど。ここらへんの話は
                          http://www.boost.org/libs/test/doc/html/utf/intro.html に。
               12/02/11                     Boost.勉強会 #8 大阪                      35
What's the Boost.Test?
                    長い説明もつまらないのでちょっと
Introduction
                ●
  What's
 Features           使ってみる。
How to use
Conclusion




               12/02/11     Boost.勉強会 #8 大阪   36
What's the Boost.Test?
 
#define BOOST_TEST_MODULE SimpleTest
#include <boost/test/unit_test.hpp>


BOOST_AUTO_TEST_SUITE(simple_test_suite)
 
BOOST_AUTO_TEST_CASE(simple_test) {
    BOOST_CHECK_EQUAL(2+2, 4);
}
 
BOOST_AUTO_TEST_SUITE_END()

12/02/11             Boost.勉強会 #8 大阪       37
What's the Boost.Test?
//テストモジュールの定義
#define BOOST_TEST_MODULE SimpleTest
#include <boost/test/unit_test.hpp>

//テストスイートの定義とテストモジュールへの追加
BOOST_AUTO_TEST_SUITE(simple_test_suite)
//テストケースの定義とテストスイートへの追加
BOOST_AUTO_TEST_CASE(simple_test) {
    BOOST_CHECK_EQUAL(2+2, 4);
}

BOOST_AUTO_TEST_SUITE_END()
12/02/11             Boost.勉強会 #8 大阪       38
What's the Features?




12/02/11         Boost.勉強会 #8 大阪   39
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
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
What's the Features?
Introduction
  What's
                ●   Usage Variant
 Features
How to use
                ●   Testをする状況や環境に合わせて4
Conclusion
                    種類のUTFの使用法が用意されてい
                    る。




               12/02/11         Boost.勉強会 #8 大阪   42
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
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
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
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
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
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
What's the Features?
                    テストランナー(Test Runner)
Introduction
                ●
  What's

                    テストの実行を管理する
 Features
                ●
How to use
Conclusion          ●
                          テストモジュールのエントリポイント
                    ●     実行時パラメータ(コマンドライン引数など)
                          からUTFを初期化する
                    ●     ログとテストのレポート用にOutputを準備
                    ●
                          などなど・・・




               12/02/11          Boost.勉強会 #8 大阪   49
What's the Features?
                    テストランナー(Test Runner)
Introduction
                ●
  What's

                    ビルトイン以外のテストランナーを
 Features
                ●
How to use
Conclusion          使用することができる。
                    (先進的なテストランナーはGUIや
                    テストカバレッジの機能を備えてい
                    るかも)
                    (でも見たことない)
                ●
                    今日は扱いません。あとよく分かり
                    ません。
                          語りえぬものについては、沈黙しなければ
                          ならない
               12/02/11         Boost.勉強会 #8 大阪   50
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
What's the Features?
                    モジュール初期化関数
Introduction
                ●
  What's

                    テストツリーを構築するなど…?
 Features
                ●
How to use

                    ほとんどビルトインのもので済むの
Conclusion
                ●

                    で使わなくても大丈夫
                ●
                    今日は扱いません。あとよく分かり
                    ません。
                          語りえぬものについては、沈黙しなければ
                          ならない



               12/02/11         Boost.勉強会 #8 大阪   52
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
What's the Features?
                    テストの定義と組織化
Introduction
                ●
  What's
 Features
How to use
Conclusion      ●
                    テストケースを作成
                ●
                    テストケースをテストスイートにグ
                    ループ化できる
                ●
                    テストスイートをさらに大きなテス
                    トスイートにグループ化できる



               12/02/11       Boost.勉強会 #8 大阪   54
What's the Boost.Test?( 再掲 )
//テストモジュールの定義
#define BOOST_TEST_MODULE SimpleTest
#include <boost/test/unit_test.hpp>

//テストスイートの定義とテストモジュールへの追加
BOOST_AUTO_TEST_SUITE(simple_test_suite)
//テストケースの定義とテストスイートへの追加
BOOST_AUTO_TEST_CASE(simple_test) {
    BOOST_CHECK_EQUAL(2+2, 4);
}

BOOST_AUTO_TEST_SUITE_END()
12/02/11             Boost.勉強会 #8 大阪       55
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
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
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
What's the Features?
                    テストの定義と組織化
Introduction
                ●
  What's

                    テストケースはテストスイートのなか
 Features
                ●

                    に複数含めることができる。
How to use
Conclusion

                ●
                    テストスイートは入れ子になること
                    ができる。




               12/02/11       Boost.勉強会 #8 大阪   59
What's the Boost.Test?
#include <boost/test/unit_test.hpp>
BOOST_AUTO_TEST_SUITE(suite1)

      BOOST_AUTO_TEST_SUITE(suite2)

           BOOST_AUTO_TEST_CASE(test1) { /**/ }
           BOOST_AUTO_TEST_CASE(test2) { /**/ }

      BOOST_AUTO_TEST_SUITE_END()

      BOOST_AUTO_TEST_CASE(test3) { /**/ }

BOOST_AUTO_TEST_SUITE_END()
12/02/11                Boost.勉強会 #8 大阪           60
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
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
What's the Features?
Introduction
  What's
                ●   Fixture
                    テストケースなどで以下の役割を担
 Features
                ●
How to use
Conclusion          う
                    ●
                          テスト開始前に状態を整える
                    ●
                          テストに関する特定の状態を用意する
                    ●
                          テスト終了後にクリーンアップをする




               12/02/11         Boost.勉強会 #8 大阪   63
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
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
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
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
What's the Features?
Introduction
  What's
                ●   Fixture
                    テストケースなどで以下の役割を担
 Features
                ●
How to use
Conclusion          う
                    ●
                          テスト開始前に状態を整える
                    ●
                          テストに関する特定の状態を用意する
                    ●
                          テスト終了後にクリーンアップをする




               12/02/11         Boost.勉強会 #8 大阪   68
What's the Features?
Introduction
  What's
                ●   Fixture
 Features
How to use
                ●   3つのレベルでSetupとCleanupを行
Conclusion          うことができる
                    ●
                          テストケース
                    ●
                          テストスイート
                    ●
                          グローバル




               12/02/11         Boost.勉強会 #8 大阪   69
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
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
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
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
What's the Boost.Test?
struct F1 {
    F1() {
         std::cout << "F1" << std::endl;
    }
      ~F1() {
         std::cout << "~F1" << std::endl;
    }
};
//同様にF2, F3を定義する




12/02/11             Boost.勉強会 #8 大阪        74
What's the Boost.Test?
BOOST_GLOBAL_FIXTURE(F1);
BOOST_GLOBAL_FIXTURE(F2);
BOOST_GLOBAL_FIXTURE(F3);

BOOST_AUTO_TEST_SUITE(global_fixture_test_suite)

BOOST_AUTO_TEST_CASE(global_fixture_test)
{
    //nop
}

BOOST_AUTO_TEST_SUITE_END()

12/02/11             Boost.勉強会 #8 大阪               75
What's the Boost.Test?
BOOST_GLOBAL_FIXTURE(F1);
BOOST_GLOBAL_FIXTURE(F2);
BOOST_GLOBAL_FIXTURE(F3);

BOOST_AUTO_TEST_SUITE(global_fixture_test_suite)

BOOST_AUTO_TEST_CASE(global_fixture_test)
{                             F1
    //nop                     F2
}                             F3
                              Running 1 test case...
                              ~F1
BOOST_AUTO_TEST_SUITE_END() ~F2
                              ~F3
12/02/11             Boost.勉強会 #8 大阪               76
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
What's the Features?
                    テストの出力
Introduction
                ●
  What's

                    全てのテストで統一的なレポートを
 Features
                ●
How to use
Conclusion      ●
                    エラーについて、ソース上の詳細な
                    情報を
                ●   テストのエラーの記述(test log)はテ
                    スト結果の要約(test results report)
                    とは分離する
                ●
                    柔軟な出力内容
                ●
                    柔軟な出力の形式
               12/02/11       Boost.勉強会 #8 大阪      78
What's the Features?
                    テストの出力
Introduction
                ●
  What's
 Features
How to use
                ●   Test Log
Conclusion
                ●   Test Report
                ●   Progress Display




               12/02/11           Boost.勉強会 #8 大阪   79
What's the Features?
                    テストの出力
Introduction
                ●
  What's
 Features
How to use
                ●   Test Log
Conclusion
                ●   Test Report
                ●   Progress Display




               12/02/11           Boost.勉強会 #8 大阪   80
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
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
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
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
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
What's the Features?
                    テストの出力
Introduction
                ●
  What's
 Features
How to use          BOOST_TEST_CHECKPOINT(
Conclusion            checkpoint_message)
                ●   Logに名前付きのチェックポイント
                    をさしこむ




               12/02/11       Boost.勉強会 #8 大阪   86
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
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
What's the Boost.Test?
struct MyConfig {
    MyConfig() : test_log( "example.log" )     {
            boost::unit_test::unit_test_log.set_stream( test_log );
    }
      ~MyConfig()                                  {
            boost::unit_test::unit_test_log.set_stream( std::cout );
    }
    std::ofstream test_log;
};
BOOST_GLOBAL_FIXTURE( MyConfig );
BOOST_AUTO_TEST_CASE( test_case )
{
    //...



 12/02/11                        Boost.勉強会 #8 大阪                       89
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
What's the Features?
using namespace boost::unit_test;
BOOST_AUTO_TEST_CASE( test_case0 )
{
    if ( runtime_config::log_level() <
         log_warnings )
        unit_test_log.set_threshold_level(
            log_warnings );
    BOOST_WARN( sizeof(int) > 4 );
}




12/02/11             Boost.勉強会 #8 大阪         91
What's the Features?
                    テストの出力
Introduction
                ●
  What's
 Features
How to use
                ●   Test Log
Conclusion
                ●   Test Report
                ●   Progress Display




               12/02/11           Boost.勉強会 #8 大阪   92
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
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
What's the Features?
                    テストの出力
Introduction
                ●
  What's
 Features
How to use
                ●   Test Log
Conclusion
                ●   Test Report
                ●   Progress Display




               12/02/11           Boost.勉強会 #8 大阪   95
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
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
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
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
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
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
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
What's the Features?
                    Testing tools
Introduction
                ●
  What's

                    複数のマクロと関数宣言からなる
 Features
                ●

                    ツール集。
How to use
Conclusion

                ●
                    テストの作成と管理を容易にして、
                    統一的なエラーレポーティングの仕
                    組みを提供する。
                ●
                    全てのツールは自動的にエラーレ
                    ポーティングにエラーの位置情報
                    (ファイル名と行番号)

               12/02/11       Boost.勉強会 #8 大阪   103
What's the Features?
                    Testing tools flavors
Introduction
                ●
  What's

                    全てのテストツールにはflavorsが提
 Features
                ●

                    供されている
How to use
Conclusion

                ●
                    テストツールのアサーションについ
                    てのレベル的なもの




               12/02/11       Boost.勉強会 #8 大阪   104
What's the Features?
                    Testing tools flavors
Introduction
                ●
  What's

                    WARN
 Features
                ●
How to use
Conclusion          ●
                      警告
                    ●
                      エラーカウント:そのまま
                    ●
                      テストの実行:継続




               12/02/11       Boost.勉強会 #8 大阪   105
What's the Features?
                    Testing tools flavors
Introduction
                ●
  What's

                    CHECK
 Features
                ●
How to use
Conclusion          ●
                      エラーチェック
                    ●
                      エラーカウント:増加
                    ●
                      テストの実行:継続




               12/02/11        Boost.勉強会 #8 大阪   106
What's the Features?
                    Testing tools flavors
Introduction
                ●
  What's

                    REQUIRE
 Features
                ●
How to use
Conclusion          ●
                      必要条件チェック
                    ●
                      エラーカウント:増加
                    ●
                      テストの実行:中断




               12/02/11        Boost.勉強会 #8 大阪   107
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
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
What's the Features?
                    提供されているTesting tools
Introduction
                ●
  What's

                    などなど・・・
 Features
                ●
How to use
Conclusion      ●
                    詳しくはドキュメントに書いてあり
                    ます。




               12/02/11       Boost.勉強会 #8 大阪   110
What's the Features?
                    提供されているTesting tools
Introduction
                ●
  What's

                    Testing toolsを使うことでテストの
 Features
                ●

                    意味を分かりやすく書くことがで
How to use
Conclusion

                    き、さらに統一的なエラーレポー
                    ティングができるようになる。




               12/02/11       Boost.勉強会 #8 大阪   111
How to use the Boost.Test




12/02/11            Boost.勉強会 #8 大阪    112
How to use the Boost.Test
                    デモ
Introduction
                ●
  What's
 Features
How to use
Conclusion




               12/02/11    Boost.勉強会 #8 大阪   113
Conclusion




12/02/11    Boost.勉強会 #8 大阪   114
Conclusion
Introduction
  What's
                ●   Boost.Testを使うことで、C++のテ
 Features
                    ストを自動的に組織しながらテスト
How to use
Conclusion
                    を書くことができる。
                ●
                    実行時引数を設定することで、柔軟
                    にテストをすることができる。
                ●   Testing toolsを使うことでテスト内
                    容を明確にすることができる。
                ●   (Boostに含まれてるので)普段から
                    Boostを使っている人は導入しやす
                    い。
               12/02/11        Boost.勉強会 #8 大阪   115
Conclusion
                    欠点
Introduction
                ●
  What's

                    実行時にスキップするテストを選ぶ
 Features
                ●

                    ことが出来ない
How to use
Conclusion

                ●   Mockの仕組みがない
                ●
                    テスト出力のストリームがワイド文
                    字列対応していない




               12/02/11        Boost.勉強会 #8 大阪   116
Conclusion
                    欠点
Introduction
                ●
  What's

                    実行時にスキップするテストを選ぶ
 Features
                ●

                    ことが出来ない
How to use
Conclusion

                ●   Mockの仕組みがない
                ●
                    テスト出力のストリームがワイド文
                    字列対応していない




               12/02/11        Boost.勉強会 #8 大阪   117
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
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
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
Conclusion
                    質問など・・・
Introduction
                ●
  What's
 Features
How to use
Conclusion




               12/02/11        Boost.勉強会 #8 大阪   121
Thank You!
           ありがとうございました!



12/02/11      Boost.勉強会 #8 大阪   122

More Related Content

PDF
テスト文字列に「うんこ」と入れるな
PDF
プログラミングコンテストでの動的計画法
PDF
プログラムを高速化する話
PDF
メルカリ・ソウゾウでは どうGoを活用しているのか?
PDF
RSA暗号運用でやってはいけない n のこと #ssmjp
PDF
勉強か?趣味か?人生か?―プログラミングコンテストとは
PPTX
DAUを評価指標から捨てた会社の話 #tokyowebmining
PPTX
おすすめVimプラグインまとめ
テスト文字列に「うんこ」と入れるな
プログラミングコンテストでの動的計画法
プログラムを高速化する話
メルカリ・ソウゾウでは どうGoを活用しているのか?
RSA暗号運用でやってはいけない n のこと #ssmjp
勉強か?趣味か?人生か?―プログラミングコンテストとは
DAUを評価指標から捨てた会社の話 #tokyowebmining
おすすめVimプラグインまとめ

What's hot (20)

PDF
Rolling Hashを殺す話
PDF
目grep入門 +解説
PDF
レコメンドアルゴリズムの基本と周辺知識と実装方法
PDF
Marp Tutorial
PDF
型安全性入門
PDF
ゼロから始める転移学習
PDF
Redmineチューニングの実際と限界(旧資料) - Redmine performance tuning(old), See Below.
PDF
見やすいプレゼン資料の作り方 - リニューアル増量版
PDF
研究分野をサーベイする
PDF
「のどが渇いた」というユーザーに何を出す? ユーザーの「欲しい」に惑わされない、本当のインサイトを見つけるUXデザイン・UXリサーチ
PDF
プレゼンの技術
PDF
ユークリッド最小全域木
PDF
実践・最強最速のアルゴリズム勉強会 第一回 講義資料(ワークスアプリケーションズ & AtCoder)
PDF
例外設計における大罪
PDF
DX時代のITエンジニアに送る、アジャイル式「いきいき」ヘルスマネジメント
PDF
IT系エンジニアのためのプレゼンテーション入門
PDF
TDD のこころ @ OSH2014
PPT
Glibc malloc internal
PPTX
クソザコ鳥頭が非順序連想コンテナに入門してみた
PDF
Yahoo! ニュースにおける ドキュメント管理の事例紹介
Rolling Hashを殺す話
目grep入門 +解説
レコメンドアルゴリズムの基本と周辺知識と実装方法
Marp Tutorial
型安全性入門
ゼロから始める転移学習
Redmineチューニングの実際と限界(旧資料) - Redmine performance tuning(old), See Below.
見やすいプレゼン資料の作り方 - リニューアル増量版
研究分野をサーベイする
「のどが渇いた」というユーザーに何を出す? ユーザーの「欲しい」に惑わされない、本当のインサイトを見つけるUXデザイン・UXリサーチ
プレゼンの技術
ユークリッド最小全域木
実践・最強最速のアルゴリズム勉強会 第一回 講義資料(ワークスアプリケーションズ & AtCoder)
例外設計における大罪
DX時代のITエンジニアに送る、アジャイル式「いきいき」ヘルスマネジメント
IT系エンジニアのためのプレゼンテーション入門
TDD のこころ @ OSH2014
Glibc malloc internal
クソザコ鳥頭が非順序連想コンテナに入門してみた
Yahoo! ニュースにおける ドキュメント管理の事例紹介
Ad

Viewers also liked (7)

PDF
Boost sg msgpack
PDF
C++コミュニティーの中心でC++をDISる
PDF
C++14 enum hash
PDF
Boost.Timer
PPTX
Pub/Sub model, msm, and asio
PDF
Glfw3,OpenGL,GUI
PDF
C++14 solve explicit_default_constructor
Boost sg msgpack
C++コミュニティーの中心でC++をDISる
C++14 enum hash
Boost.Timer
Pub/Sub model, msm, and asio
Glfw3,OpenGL,GUI
C++14 solve explicit_default_constructor
Ad

Similar to Introduction to boost test (20)

PDF
Study3 boost
PDF
Boost Overview
PDF
Boost Tour 1.50.0
PDF
Boost Tour 1_58_0 merge
PDF
C++ Now 2012 report
PDF
Boost Tour 1.53.0 merge
PPTX
エラーハンドリング
PDF
Boost tour 1.60.0 merge
PDF
boost and c++11
PDF
Boost tour 1.60.0
PDF
Boost Tour 1.53.0
PDF
Boost.Study 14 Opening
PDF
Replace Output Iterator and Extend Range JP
PDF
xUnit Test Patterns - Chapter19
PDF
Boost Fusion Library
PDF
xUTP Chapter19 (2). Testcase Class
PDF
El text.tokuron a(2019).watanabe190606
PDF
TDDワークショップ(第2回)
PDF
Boost tour 1_40_0
PDF
Boost tour 1_44_0
Study3 boost
Boost Overview
Boost Tour 1.50.0
Boost Tour 1_58_0 merge
C++ Now 2012 report
Boost Tour 1.53.0 merge
エラーハンドリング
Boost tour 1.60.0 merge
boost and c++11
Boost tour 1.60.0
Boost Tour 1.53.0
Boost.Study 14 Opening
Replace Output Iterator and Extend Range JP
xUnit Test Patterns - Chapter19
Boost Fusion Library
xUTP Chapter19 (2). Testcase Class
El text.tokuron a(2019).watanabe190606
TDDワークショップ(第2回)
Boost tour 1_40_0
Boost tour 1_44_0

More from Kohsuke Yuasa (10)

PDF
オーディオ用レベルメータを作ってみよう
PDF
Juceで作るオーディオアプリケーション
PDF
C++ マルチスレッドプログラミング
PDF
イマドキC++erのモテカワリソース管理術
PDF
最近のC++ @ Sapporo.cpp #5
PDF
規格書で読むC++11のスレッド
PDF
C++ ポインタ ブートキャンプ
PDF
C++ template-primer
PDF
Read egg oven
PDF
Sapporocpp#2 exception-primer
オーディオ用レベルメータを作ってみよう
Juceで作るオーディオアプリケーション
C++ マルチスレッドプログラミング
イマドキC++erのモテカワリソース管理術
最近のC++ @ Sapporo.cpp #5
規格書で読むC++11のスレッド
C++ ポインタ ブートキャンプ
C++ template-primer
Read egg oven
Sapporocpp#2 exception-primer

Recently uploaded (7)

PPTX
生成AIとモデルベース開発:実はとても相性が良いことを説明します。まあそうだろうなと思われる方はご覧ください。
PDF
AIシステムのセキュリティ:脅威となりつつあるAIの現状と課題 [English] Security of AI Systems: The Current...
PDF
20250826_Devinで切り拓く沖縄ITの未来_AI駆動開発勉強会 沖縄支部 第2回
PDF
翔泳社 「C++ ゼロからはじめるプログラミング」対応 C++学習教材(三谷純)
PDF
ココロ分解帳|感情をやさしく分解し自分と他者を理解するためのモバイルノートアプリ
PDF
Working as an OSS Developer at Ruby Association Activity Report 2025
生成AIとモデルベース開発:実はとても相性が良いことを説明します。まあそうだろうなと思われる方はご覧ください。
AIシステムのセキュリティ:脅威となりつつあるAIの現状と課題 [English] Security of AI Systems: The Current...
20250826_Devinで切り拓く沖縄ITの未来_AI駆動開発勉強会 沖縄支部 第2回
翔泳社 「C++ ゼロからはじめるプログラミング」対応 C++学習教材(三谷純)
ココロ分解帳|感情をやさしく分解し自分と他者を理解するためのモバイルノートアプリ
Working as an OSS Developer at Ruby Association Activity Report 2025

Introduction to boost test

  • 1. Boost.Testの紹介 @hotwatermorning 12/02/11 Boost.勉強会 #8 大阪 1
  • 2. 自己紹介 ● @hotwatermorning ● 札幌から来ました 12/02/11 Boost.勉強会 #8 大阪 2
  • 3. 自己紹介 ● @hotwatermorning ● 札幌から来ました ● 今季は水道が2回凍結 しました。 12/02/11 Boost.勉強会 #8 大阪 3
  • 4. 自己紹介 ● 2011年は、 <= C++の同人誌書いたり、 Boost.勉強会 #6 @札幌を 開催したりしました => http://www.flickr.com/photos/miio119/6318681082/ 12/02/11 Boost.勉強会 #8 大阪 4
  • 5. Introduction 12/02/11 Boost.勉強会 #8 大阪 5
  • 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
  • 9. What's the Boost.Test? 12/02/11 Boost.勉強会 #8 大阪 9
  • 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
  • 16. What's the Boost.Test? #include <stdexcept> #include <iostream> #include <boost/test/execution_monitor.hpp> #include <boost/test/utils/basic_cstring/io.hpp> int foo() { throw std::runtime_error("some error has occured"); return 0; } int main() { boost::execution_monitor mon; try { return mon.execute(foo); ᅠ ᅠ ᅠ } catch(boost::execution_exception const &e) { ᅠ ᅠ ᅠ ᅠ std::cout << e.what() << std::endl; ᅠ ᅠ } } 12/02/11 Boost.勉強会 #8 大阪 16
  • 17. What's the Boost.Test? Introduction What's ● Execution Monitor Features How to use ● Boost.Testの基礎 受け取れる例外は、 Conclusion ● ● C文字列 ● std::string ● std::exceptionから派生したクラス の3種類。 ● これ以外の例外をExecution Monitorで捕捉 したい場合はexecution_monitorの register_exception_translatorを使用する。 12/02/11 Boost.勉強会 #8 大阪 17
  • 18. What's the Boost.Test? struct my_error { my_error(int code) : code_(code) {} int code_; }; void trns_my_error(my_error const& e) { throw std::domain_error(e.code_ == 0 ? "code is zero" : "otherwise"); } int main() { boost::execution_monitor mon; mon.register_exception_translator<my_error>(&trns_my_error); try { return mon.execute(bar); //bar may throw my_error. } catch(boost::execution_exception const &e) { std::cout << e.what() << std::endl; } } 12/02/11 Boost.勉強会 #8 大阪 18
  • 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
  • 22. 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; } 12/02/11 Boost.勉強会 #8 大阪 22
  • 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
  • 33. Requirements of UTF ● シンプルで、使い始めの人にも分かりやすくユニットテ ストモジュールが書けるべき ● 上級者が自明でないようなテストをすることも可能であ るべき ● テストモジュールはたくさんの小さなテストケースを持 つことができ、開発者がそれをテストスイートにグルー プ化することができるべき ● 開発初期にはユーザーは詳細で説明的なエラーメッセー ジを見たい。しかし回帰テスト中にはどのテストが失敗 したかだけを知りたい。 12/02/11 Boost.勉強会 #8 大阪 33
  • 34. Requirements of UTF(Cont'd) ● 小さいテストモジュールの実行時間>コンパイル時間で あるべき。実行に1秒しかかからないテストのコンパイ ルに1分も待ちたくはない。 ● 長く複雑なテストではユーザーはテストの進捗を見られ るようにしたい。 ● 簡単なテストは外部ライブラリを必要とするべきではな い。 ● 長期的な使用のためにユニットテストフレームワークは スタンドアロンなライブラリとしてビルドできるべき。 12/02/11 Boost.勉強会 #8 大阪 34
  • 35. What's the Boost.Test? Introduction What's ● UTFの設計はこれらをベースにして Features いる。そしてUTFは多岐に渡る機能 を提供する How to use Conclusion ● さまざまなTesting toolsを使用することで簡 単にテストを書くことができる。 ● 一つのテストツリーの中にテストケースを組 織化できる。 ● 面倒なエラー検出とレポーティングの義務 とフレームワークの実行時パラメータ処理 からあなたを解放する。 などなど。ここらへんの話は http://www.boost.org/libs/test/doc/html/utf/intro.html に。 12/02/11 Boost.勉強会 #8 大阪 35
  • 36. What's the Boost.Test? 長い説明もつまらないのでちょっと Introduction ● What's Features 使ってみる。 How to use Conclusion 12/02/11 Boost.勉強会 #8 大阪 36
  • 37. What's the Boost.Test?   #define BOOST_TEST_MODULE SimpleTest #include <boost/test/unit_test.hpp> BOOST_AUTO_TEST_SUITE(simple_test_suite)   BOOST_AUTO_TEST_CASE(simple_test) { BOOST_CHECK_EQUAL(2+2, 4); }   BOOST_AUTO_TEST_SUITE_END() 12/02/11 Boost.勉強会 #8 大阪 37
  • 38. What's the Boost.Test? //テストモジュールの定義 #define BOOST_TEST_MODULE SimpleTest #include <boost/test/unit_test.hpp> //テストスイートの定義とテストモジュールへの追加 BOOST_AUTO_TEST_SUITE(simple_test_suite) //テストケースの定義とテストスイートへの追加 BOOST_AUTO_TEST_CASE(simple_test) { BOOST_CHECK_EQUAL(2+2, 4); } BOOST_AUTO_TEST_SUITE_END() 12/02/11 Boost.勉強会 #8 大阪 38
  • 39. What's the Features? 12/02/11 Boost.勉強会 #8 大阪 39
  • 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
  • 55. What's the Boost.Test?( 再掲 ) //テストモジュールの定義 #define BOOST_TEST_MODULE SimpleTest #include <boost/test/unit_test.hpp> //テストスイートの定義とテストモジュールへの追加 BOOST_AUTO_TEST_SUITE(simple_test_suite) //テストケースの定義とテストスイートへの追加 BOOST_AUTO_TEST_CASE(simple_test) { BOOST_CHECK_EQUAL(2+2, 4); } BOOST_AUTO_TEST_SUITE_END() 12/02/11 Boost.勉強会 #8 大阪 55
  • 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
  • 60. What's the Boost.Test? #include <boost/test/unit_test.hpp> BOOST_AUTO_TEST_SUITE(suite1) BOOST_AUTO_TEST_SUITE(suite2) BOOST_AUTO_TEST_CASE(test1) { /**/ } BOOST_AUTO_TEST_CASE(test2) { /**/ } BOOST_AUTO_TEST_SUITE_END() BOOST_AUTO_TEST_CASE(test3) { /**/ } BOOST_AUTO_TEST_SUITE_END() 12/02/11 Boost.勉強会 #8 大阪 60
  • 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
  • 74. What's the Boost.Test? struct F1 { F1() { std::cout << "F1" << std::endl; } ~F1() { std::cout << "~F1" << std::endl; } }; //同様にF2, F3を定義する 12/02/11 Boost.勉強会 #8 大阪 74
  • 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
  • 89. What's the Boost.Test? struct MyConfig { MyConfig() : test_log( "example.log" ) { boost::unit_test::unit_test_log.set_stream( test_log ); } ~MyConfig() { boost::unit_test::unit_test_log.set_stream( std::cout ); } std::ofstream test_log; }; BOOST_GLOBAL_FIXTURE( MyConfig ); BOOST_AUTO_TEST_CASE( test_case ) { //... 12/02/11 Boost.勉強会 #8 大阪 89
  • 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
  • 91. What's the Features? using namespace boost::unit_test; BOOST_AUTO_TEST_CASE( test_case0 ) { if ( runtime_config::log_level() < log_warnings ) unit_test_log.set_threshold_level( log_warnings ); BOOST_WARN( sizeof(int) > 4 ); } 12/02/11 Boost.勉強会 #8 大阪 91
  • 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
  • 114. Conclusion 12/02/11 Boost.勉強会 #8 大阪 114
  • 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
  • 122. Thank You! ありがとうございました! 12/02/11 Boost.勉強会 #8 大阪 122