- ダウンロードプロジェクトhttps://github.com/google/googletest
- 指定された場所にプロジェクトファイル
- プロジェクトファイル解凍解凍
- cmakeの./
- メイクのコンパイル
- 次に、現在のディレクトリにプロジェクトフォルダ、libフォルダ内のファイルを含めます
- MAIN.CPPファイル筆記試験、unit.h +が実装である機能、ヘッダファイル内の関数宣言、.Cを達成unit.c。
/*************************************************************************
> File Name: unit.h
> Author:
> Mail:
> Created Time: 2020年01月12日 星期日 15时47分14秒
************************************************************************/
#ifndef _UNIT_H
#define _UNIT_H
int add(int a, int b);
#endif
/*************************************************************************
> File Name: unit.c
> Author:
> Mail:
> Created Time: 2020年01月12日 星期日 15时49分42秒
************************************************************************/
#include<stdio.h>
#include"unit.h"
int add(int a, int b){
return a + b;
}
- テスト主に(ソースに固有の基準)
/*************************************************************************
> File Name: main.cpp
> Author:
> Mail:
> Created Time: 2020年01月12日 星期日 15时28分00秒
************************************************************************/
#include"unit.h"
#include<gtest/gtest.h>
#include<iostream>
using namespace std;
TEST(test, add_function){
EXPECT_EQ(add(3, 4), 7);
}
int main(int argc, char *argv[]){
::testing::InitGoogleTest(&argc, argv);
return RUN_ALL_TESTS();
}
- リンク+コンパイラでは、究極のコマンドがg ++ --std = C ++ 11 -I./include -L./lib main.cppにunit.c -lgtest -lpthreadコンパイルフェーズを達成します
- 最後に./a.out出力