LoginSignup
0

More than 3 years have passed since last update.

CppUTestのセットアップ

Posted at

CppUTestのセットアップ

C言語用のテスティングフレームワークについて、詳しく知らなかったので、調べました。今回はCppUTestを選び、セットアップ方法をまとめました。

環境

  • Ubuntu 18.04

インストールの方法

ビルドツールをインストールします。

sudo apt install -y build-essential autoconf libtool

githubのリポジトリからソースをダウンロードします。

git clone https://github.com/cpputest/cpputest.git

CppUTestをビルドします。

cd cpputest
autoreconf . -i
./configure 
make tdd

CppUTestの環境変数を設定します。

echo "export CPPUTEST_HOME=$(pwd)" >> ~/.bashrc
echo 'export PATH=$PATH:${CPPUTEST_HOME}/scripts' >> ~/.bashrc

プロジェクトの作成

CppUTestにはプロジェクトを作成するスクリプトがあります。ダウンロードしたソースには実行権限がないので、実行権限を付与します。

chmod a+x ${CPPUTEST_HOME}/scripts/NewProject.sh

プロジェクトを作成するスクリプトを実行します。

$ NewProject.sh GameOfLife
Copy template project
Project.cproject  Project.project  ProjectMakefile  include  src  tests
Change Name ./ProjectMakefile to GameOfLifeMakefile
Change Name ./Project.project to GameOfLife.project
Change Name src/util/ProjectBuildTime.cpp to GameOfLifeBuildTime.cpp
Change Name include/util/ProjectBuildTime.h to GameOfLifeBuildTime.h
Change Name tests/util/ProjectBuildTimeTest.cpp to GameOfLifeBuildTimeTest.cpp
You might want to modify the path for CPPUTEST_HOME in the Makefile.

makeを実行するとビルドとテストが行われます。

$ cd GameOfLife
$ make
compiling AllTests.cpp
compiling GameOfLifeBuildTimeTest.cpp
compiling GameOfLifeBuildTime.cpp
Building archive lib/libGameOfLife.a
a - objs/src/util/GameOfLifeBuildTime.o
Linking GameOfLife_tests
Running GameOfLife_tests
.
OK (1 tests, 1 ran, 1 checks, 0 ignored, 0 filtered out, 0 ms)

参考文献

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
0