




간단한 테스트 (GoogleTestQuickStart)
#include <gtest/gtest.h>
#include <iostream>
int add(int a, int b) { return a + b; } //테스트 할 함수
TEST(TestSample, TestAddition) { ASSERT_EQ(2, add(1, 1)); } //테스트 코드
int main(int argc, char **argv) {
testing::InitGoogleTest(&argc, argv);
return RUN_ALL_TESTS();
}
간단한 테스트 (GoogleTestSimple)
#include "library_code.h"
#include <gtest/gtest.h>
#include <iostream>
TEST(TestCountPositives, BasicTest) {
// Arrange
std::vector<int> input_vector{1, -2, 3, -4, 5, -6, -7};
// Act
int count = CountPositives(input_vector);
// Assert
ASSERT_EQ(3, count);
}
TEST(TestCountPositives, EmptyVectorTest) {
// Arrange
std::vector<int> input_vector{};
// Act
int count = CountPositives(input_vector);
// Assert
ASSERT_EQ(0, count);
}
TEST(TestCountPositives, AllNegativesTest) {
// Arrange
std::vector<int> input_vector{-1, -2, -3};
// Act
int count = CountPositives(input_vector);
// Assert
ASSERT_EQ(0, count);
}
int main(int argc, char **argv) {
testing::InitGoogleTest(&argc, argv);
return RUN_ALL_TESTS();
}
#ifndef LIBRARY_CODE_H_
#define LIBRARY_CODE_H_
#include <vector>
int CountPositives(std::vector<int> const &input_vector);
#endif // LIBRARY_CODE_H_