You are on page 1of 17

Build GoogleTest 1.10.

0 Dengan Visual C++ 2015 Enterprise


https://mkkhedawat.github.io/Installing-and-Using-GoogleTest-with-Visual-Studio/

https://www.programmersought.com/article/50126133146/

Tools :

Dependensi : Python 2.7

Kompiler C++ : Visual C++ 2015 (Versi minimal kompiler C++ wajib untuk GTest versi 1.10.0 keatas)

Build Tools : CMake versi 3.21.0

Testing Framework : GoogleTest 1.10.0

Sistem Operasi : Windows 8.1 x64

1. Persiapan

Pilih Install for all users


Semua pilihan jangan ada tanda ‘X’

Pastikan CMake & Python ada di environment variable


2. Build GoogleTest 1.10.0 Dengan CMake

Build GoogleTest dari source dengan CMAKE. Tulis : cmake -S C:\gtes110\googletest-1.10.0_source -B


C:\gtes110\googletest-1.10.0_target

-S : folder asal yang berisi source code GoogleTest 1.10.0

-B : folder kosong yang jadi tujuan hasil building

Build GoogleTest 1.10.0 project selesai


Hasil build dari CMake

3. Build GoogleTest 1.10.0 Library


Pilih file googletest-distribution.sln

Klik Build Solution untuk mode Debug & Release


Pastikan hasilnya 0 failed

Hasil Build Solution mode Debug

Hasil Build Solution mode Release


4. Tes Testing Framework GoogleTest 1.10.0 Yang Sudah Dibuat

Tulis nama proyeknya


Tulis contoh kode ini

#include <stdio.h>
#include "gtest/gtest.h"

int main() {
printf("this is a tes, only test, of course this only test");

char *StrBlocked = “ ”;
gets_s(StrBlocked, 10);

return 0;
}

Begitu kode dikompilasi akan ada error no such file or directory ‘gtest/gtest.h’.

A. Copy file2 header & source GoogleMock

Copy folder include & src

Paste disitu
B. Copy file2 header & source GoogleTest

Copy folder include & src

Paste disitu

C. Copy file2 library GoogleMock & GoogleTest

Copy folder lib


Paste disitu

D. Konfigurasi Di Tes Project

Klik Properties
Configuration : mode Active (Debug)

Configuration Properties  VC++ Directories  Include Directories  Masukkan lokasi file2 header &
source GoogleTest
Configuration: mode Debug

Configuration Properties  VC++ Directories  Include Directories  Masukkan lokasi file2 library
mode Debug
Configuration : mode Debug

Configuration Properties  Linker  General  Additional Library Directories  Masukkan lokasi


folder lib
Configuration: mode Debug

Configuration Properties  Linker  Input  tulis nama file library mode Debug
Configuration: mode (Active) Debug

Configuration Properties  C/C++  Code Generation  Runtime Library  pilih Multi-threaded


Debug (/MTd)

Edit kode yang tadi menjadi sbb :

#include <stdio.h>
#include "gtest/gtest.h"

int isSheldonInsane() {
return -1;
}

TEST(BigBangTheory, isSheldonInsaneTests) {
EXPECT_EQ(1, isSheldonInsane());
}

int main() {
printf("this is a tes, only test, of course this only test");

char *StrBlocked;
gets_s(StrBlocked, 10);

return 0;
}

Compile kode
pastikan hasil kompilasi 0 failed. Selanjutnya Build  Solution

Pastikan hasil build nya 0 failed

Run program dengan Debug  Start Without Debugging

Selesai
Produced By : C++ Coder In Jakarta

You might also like