LoginSignup
9
11

More than 5 years have passed since last update.

Visual Studio 2015にGoogle Testを導入する覚書

Last updated at Posted at 2016-08-13

Google Test公式

英語

googletest/googletest/docs/Primer.md
https://github.com/google/googletest/blob/master/googletest/docs/Primer.md

日本語

Google Test — Google Test ドキュメント日本語訳
http://opencv.jp/googletestdocs/index.html

Google Test 1.6 のドキュメント

やや古い(2016/08時点の最新は1.7.0.1)

インストール

公式にはVisual Studioの場合もソースからビルドせよと書かれている。
が、NuGetでモジュールが配布されている。

NuGet Gallery | Google Test v140 1.7.0.1
https://www.nuget.org/packages/googletest.v140.windesktop.static.rt-dyn/

NuGet Gallery | Google Test v140 Symbols 1.7.0.1
https://www.nuget.org/packages/googletest.v140.windesktop.static.rt-dyn.symbols/

AuthorsもGoogle Inc.となっていて公式モジュールのようだが、触れられていないのは何故。

NuGetからインストールしてみる。

ディレクトリツリー

NuGetからインストールするとpackages以下にファイルが展開される。

packages/
`-- googletest.v140.windesktop.static.rt-dyn.1.7.0.1
    |-- build
    |   |-- configurations.autopkg
    |   |-- native
    |   |   |-- default-propertiesui.xml
    |   |   |-- googletest.v140.windesktop.static.rt-dyn-propertiesui-11759879-b554-4c75-ab03-1831a619efa8.xml
    |   |   |-- googletest.v140.windesktop.static.rt-dyn.targets
    |   |   |-- include
    |   |   |   `-- gtest
    |   |   |       |-- gtest-death-test.h
    |   |   |       |-- gtest-message.h
    |   |   |       |-- gtest-param-test.h
    |   |   |       |-- gtest-param-test.h.pump
    |   |   |       |-- gtest-printers.h
    |   |   |       |-- gtest-spi.h
    |   |   |       |-- gtest-test-part.h
    |   |   |       |-- gtest-typed-test.h
    |   |   |       |-- gtest.h
    |   |   |       |-- gtest_pred_impl.h
    |   |   |       |-- gtest_prod.h
    |   |   |       `-- internal
    |   |   |           |-- custom
    |   |   |           |   |-- gtest-port.h
    |   |   |           |   |-- gtest-printers.h
    |   |   |           |   `-- gtest.h
    |   |   |           |-- gtest-death-test-internal.h
    |   |   |           |-- gtest-filepath.h
    |   |   |           |-- gtest-internal.h
    |   |   |           |-- gtest-linked_ptr.h
    |   |   |           |-- gtest-param-util-generated.h
    |   |   |           |-- gtest-param-util-generated.h.pump
    |   |   |           |-- gtest-param-util.h
    |   |   |           |-- gtest-port-arch.h
    |   |   |           |-- gtest-port.h
    |   |   |           |-- gtest-string.h
    |   |   |           |-- gtest-tuple.h
    |   |   |           |-- gtest-tuple.h.pump
    |   |   |           |-- gtest-type-util.h
    |   |   |           `-- gtest-type-util.h.pump
    |   |   `-- lib
    |   |       |-- Win32
    |   |       |   `-- v140
    |   |       |       |-- Debug
    |   |       |       |   `-- gtest.lib
    |   |       |       `-- Release
    |   |       |           `-- gtest.lib
    |   |       `-- x64
    |   |           `-- v140
    |   |               |-- Debug
    |   |               |   `-- gtest.lib
    |   |               `-- Release
    |   |                   `-- gtest.lib
    |   `-- publisher-info.txt
    `-- googletest.v140.windesktop.static.rt-dyn.1.7.0.1.nupkg

16 directories, 38 files

また、packages.confが作成され、以下が書き込まれる。

packages.conf
<?xml version="1.0" encoding="utf-8"?>
<packages>
  <package id="googletest.v140.windesktop.static.rt-dyn" version="1.7.0.1" targetFramework="native" />
</packages>

制限事項

NuGetでインストールしたパッケージにはgtest_main.libが含まれていない。
そのため、テスト用のmain関数を書く必要がある。

Primerよりmain関数
int main(int argc, char **argv) {
  ::testing::InitGoogleTest(&argc, argv);
  return RUN_ALL_TESTS();
}

ビルド方法参考

C++ Tutorial: Google Test (gtest) - 2016
http://www.bogotobogo.com/cplusplus/google_unit_test_gtest.php

9
11
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
9
11