Google Test(GTest) on Ubuntu 16.04
개발용 라이브러리 설치
sudo apt-get install libgtest-dev
컴파일 및 설치
sudo apt-get install cmake테스트코드
cd /usr/src/gtest/
sudo cmake CMakeLists.txt
sudo make
sudo cp *.a /usr/lib
#include <gtest/gtest.h>
#include <stdio.h>
#include <string.h>
int getBuildNumber(char* build, char* project)
{
char* p = NULL;
if (build == NULL || project == NULL) {
return -1;
}
if (strlen(build) <= strlen(project)) {
return -1;
}
if (strstr(build, project) == NULL) {
return -1;
}
p = build + strlen(project);
return atoi(p);
}
TEST(getBuildNumberTest, HandlesPositiveInput)
{
EXPECT_EQ(1301, getBuildNumber("ABC1301", "ABC"));
EXPECT_EQ(1401, getBuildNumber("ABC1401", "ABC"));
EXPECT_EQ(-1, getBuildNumber("CIH1401", "ABC"));
EXPECT_EQ(-1, getBuildNumber("CIH1401", "ABC"));
EXPECT_TRUE(strcmp("ABC1400", "ABC1301") > 0);
EXPECT_TRUE(strcmp("ABC1400", "ABC1400") == 0);
EXPECT_TRUE(strcmp("ABC1400", "ABC1401") < 0);
}
int main(int argc, char* argv[])
{
testing::InitGoogleTest(&argc, argv);
RUN_ALL_TESTS();
return 0;
}
결과
$ ./getBuildNumber
[==========] Running 1 test from 1 test case.
[----------] Global test environment set-up.
[----------] 1 test from getBuildNumberTest
[ RUN ] getBuildNumberTest.HandlesPositiveInput
[ OK ] getBuildNumberTest.HandlesPositiveInput (0 ms)
[----------] 1 test from getBuildNumberTest (0 ms total)
[----------] Global test environment tear-down
[==========] 1 test from 1 test case ran. (0 ms total)
[ PASSED ] 1 test.
Getting Start : https://github.com/google/googletest/blob/master/googletest/docs/Primer.md
출처 : https://www.eriksmistad.no/getting-started-with-google-test-on-ubuntu/
댓글
댓글 쓰기