본문 바로가기

TA(Test Automation)

googletest VSCODE C/C++

728x90

 

//main.cpp
#include <iostream>

// 덧셈 함수
int add(int a, int b) {
    return a + b;
}

int main() {
    int num1, num2;

    std::cout << "Enter the first number: ";
    std::cin >> num1;

    std::cout << "Enter the second number: ";
    std::cin >> num2;

    int sum = add(num1, num2);

    std::cout << "The sum is: " << sum << std::endl;

    return 0;
}
//test.cpp
#include <gtest/gtest.h>

// 덧셈 함수
int add(int a, int b) {
    return a + b;
}

// 테스트 케이스
TEST(AdditionTest, HandlesPositiveNumbers) {
    EXPECT_EQ(add(2, 3), 5);
}

TEST(AdditionTest, HandlesNegativeNumbers) {
    EXPECT_EQ(add(-2, -3), -5);
}

 


setup env : 

step [1]

- in git bash terminal

git clone https://github.com/google/googletest.git

 

step [2]

install gcc & g++ to cygwin

https://github.com/google/googletest.git

 

 

vscode

 

 

operation in cygwin terminal: 

 

step [1] cd D:

step [2] cd googletest/build

step [3] cmake -G "Ninja" -DMAKE_C_COMPILER="/usr/bin/gcc" -DCMAKE_CXX_COMPILER="/usr/bin/g++" ..

step [4] ninja

 

step [5]

g++ -o test test.cpp 

-I"/cygdrive/d/googletest/googletest/include" -L"/cygdrive/d/googletest/build/lib" -lgtest_main -lgtest -pthread

 

step [6] 

g++ -o main main.cpp

 

step[7]

./test

 

 

 

 

728x90