5
3

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

CppUTestの導入メモ

Posted at

背景

テスト駆動開発による組み込みプログラミングをやろうと思ったら思ったより導入に手間取ったため。

目標

  • CppUTest本体のビルド、インストール
  • テスト駆動開発による組み込みプログラミングが提供するサンプルコードのビルド、実行
  • Windows(Visual Studio)とLinux両方で環境構築

環境

  • Windows
    • Visual Studio2019
  • Linux
    • Ubuntu 18.04 on VirtualBox6.1

CppUTest本体のビルド、インストール

共通

Windows

  • cpputestフォルダ内のCppUTest_VS201x.slhをダブルクリック
  • プロジェクトの変換等の画面がでるが、全てOKで次へ。
  • ソリューションをビルド
    • Debugの場合、libフォルダにCppUTestd.libが生成される。
    • ReleaseでもビルドをするとCppUTest.libが生成される。
    • 違いがあるかはわからないがx86,x64でそれぞれビルドしてlibファイルを生成しておく。
  • cpputestフォルダのある場所をCPPUTEST_HOMEとして環境変数に追加

Linux

  • 以下のコマンドを実行
bash
$ cd cpputest                                            // cpputestディレクトリ内へ移動
$ sudo apt install build-essential autoconf libtool      // 必要なライブラリをインストール
$ bash autogen.sh                                        // autoreconfを実行
$ ./configure                                            // makefileを生成
$ make                                                   // ファイル生成
$ make check                                             // これはやらなくてもいいかも
$ make tdd                                               // テストモジュールを実行し結果を確認
$ echo "export CPPUTEST_HOME=$(pwd)" >> ~/.bash_profile  // .bash_profileに環境変数CPPUTEST_HOMEを追加
$ source ~/.bash_profile                                 // 環境変数を反映
$ sudo make install                                      // cpputestをインストール
$ sudo ./scripts/InstallScripts.sh                       // スクリプトをインストール

サンプルプログラムの実行

共通

ホームページからコードを落としておくhttps://pragprog.com/titles/jgade/source_code

Windows

  • codeフォルダ内にあるBookCode.dswを起動
  • プロジェクトの変換を尋ねられるが全てOKで先へ進む。
  • 構成プロパティ→C/C++→コード生成→関数レベルでリンクするの項目が「いいえ(/Gy-)」となっているので空欄にする。
    • AllTest_CppUTestとProductionCodeLib両方とも同じ設定にする。
  • 構成プロパティ→C/C++→全般→追加のインクルードディレクトリで、$(CPPU_U_TEST)と記載されたパスがあるので$(CPPUTEST_HOME)に書き換える。
    • AllTest_CppUTestとProductionCodeLib両方とも同じ設定にする。
  • 構成プロパティ→リンカ―→入力→追加の依存ファイルで以下の設定を行う.
    • $(CPPU_U_TEST)と記載されたパスがあるので$(CPPUTEST_HOME)に書き換える。
    • cpputest.libとなっているものをCppUTestd.libに書き換える。
      • サンプルプログラムがDebugにしか対応していないとのことなのでデバッグ版ライブラリを指定。
    • この変更はAllTest_CppUTestのみ
  • ソリューションのビルドを実行
    • 問題がなければ正常に終了
  • デバッグを実行してみてOK (127 tests, 126 ran, 525 checks, 1 ignored, 0 filtered out, 10 ms)と表示されたら成功。

Linux

  • codeディレクトリへ移動しCppUTestだけ実行したいので、make -i -f MakefileCppuTest.mkを実行
  • 1か所エラーが発生するので、コードを修正して再度ビルド。
  • OK (127 tests, 126 ran, 525 checks, 1 ignored, 0 filtered out, 1 ms)と表示されたら成功。
5
3
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
5
3

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?