Skip to content

Instantly share code, notes, and snippets.

@ishidur
Last active May 8, 2019 08:22
Show Gist options
  • Select an option

  • Save ishidur/d4005d96a5a224145084e5c31db311eb to your computer and use it in GitHub Desktop.

Select an option

Save ishidur/d4005d96a5a224145084e5c31db311eb to your computer and use it in GitHub Desktop.
Travis CIでGoogle Testを実行するための設定
language: cpp
sudo: false
matrix:
include:
# works on Precise and Trusty
- os: linux
addons:
apt:
sources:
- ubuntu-toolchain-r-test
- george-edison55-precise-backports
packages:
- g++-5
- cmake
- libgtest-dev
env:
- MATRIX_EVAL="CC=gcc-5 && CXX=g++-5"
# works on Precise and Trusty
- os: linux
addons:
apt:
sources:
- ubuntu-toolchain-r-test
- george-edison55-precise-backports
packages:
- g++-6
- cmake
- libgtest-dev
env:
- MATRIX_EVAL="CC=gcc-6 && CXX=g++-6"
# works on Precise and Trusty
- os: linux
addons:
apt:
sources:
- ubuntu-toolchain-r-test
- george-edison55-precise-backports
packages:
- g++-7
- cmake
- libgtest-dev
env:
- MATRIX_EVAL="CC=gcc-7 && CXX=g++-7"
before_install :
- eval "${MATRIX_EVAL}"
- git submodule update --init --recursive
install:
- cd /usr/src/gtest && sudo cmake . && sudo cmake --build . && sudo mv libg* /usr/local/lib/ ; cd -
script:
- g++ --version
- cd {path/to/your/test_dir}
- make && ./gtest_main
- cd ../..
git:
submodule: false
/*
* This is Example of Test Class
*/
#include <gtest/gtest.h>
#include "../Block.h"
#include "Eigen/Core"
class BlockTest : public ::testing::Test{
protected:
std::vector<Block> blocks;
BlockTest(){
blocks.emplace_back(Eigen::Vector2d(0.0,0.0), 20.0);
blocks.emplace_back(Eigen::Vector2d(10.0,0.0), 30.0);
blocks.emplace_back(Eigen::Vector2d(0.0,100.0), 100.0);
}
};
TEST_F(BlockTest, size)
{
EXPECT_EQ(20.0, blocks[0].size);
EXPECT_EQ(30.0, blocks[1].size);
EXPECT_EQ(100.0, blocks[2].size);
}
TEST_F(BlockTest, pos)
{
EXPECT_EQ(Eigen::Vector2d(0.0,0.0), blocks[0].pos);
EXPECT_EQ(Eigen::Vector2d(10.0,0.0), blocks[1].pos);
EXPECT_EQ(Eigen::Vector2d(0.0,100.0), blocks[2].pos);
}
//TODO: add propagation test and back propagation test here
#include <gtest/gtest.h>
int main(int argc, char **argv) {
::testing::InitGoogleTest(&argc, argv);
return RUN_ALL_TESTS();
}
CC = g++-7
CFLAGS = -std=gnu++1z -I {Include Files} -Wall -Wextra -pedantic
SOURCES = {Your source files}
TESTS = {Your test files}
gtest_main: gtest_main.cpp
$(CC) $(CFLAGS) -o gtest_main gtest_main.cpp ${SOURCES} ${TESTS} -lgtest -lgtest_main -pthread

Travis CIでGoogle Testを実行する

SetUp

  1. Create test directory
  2. Create gtest_main.cpp into test
  3. Create test class files into test
  4. Create Makefile into test and connect each test class to gtest_main

Done

Now, you can check build status on https://travis-ci.com/.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment