Google test

Google test

Building

  • Github
  • 配置使用Cmake
  • 测试项目:
    1.创建Win32控制台应用程序,创建完成后把include和lib文件夹拷贝到项目路径下
    2.项目配置:
    击项目属性》c/c++》代码生成中运行库中修改为“多线程调试(/MTd)”
    点击项目属性》c/c++》常规中附加包含目录中添加头文件路径
    点击项目属性》链接器》常规中附加包含目录中添加lib路径
    点击项目属性》链接器》输入中附加包依赖项中添加gtestd.lib

Inroduce

Googletest入门

Code Test

  • Test struct
    struct T1 {
    int a;
    };
    class FooTest : public ::testing::TestWithParam {
    // You can implement all the usual fixture class members here.
    // To access the test parameter, call GetParam() from class
    // TestWithParam.
    //在这里面可以实现fixture类的所有成员
    protected:
        FooTest() {
          // You can do set-up work for each test here.
        }
    
        ~FooTest() override {
          // You can do clean-up work that doesn't throw exceptions here.
        }
    
        // If the constructor and destructor are not enough for setting up
        // and cleaning up each test, you can define the following methods:
    
        void SetUp() override {
          // Code here will be called immediately after the constructor (right
          // before each test).
        }
    
        void TearDown() override {
          // Code here will be called immediately after each test (right
          // before the destructor).
        }
    
      public:
        struct T1 m_T;
      };
     //第二步
      TEST_P(FooTest, DoesBlah) {
        // Inside a test, access the test parameter with the GetParam() method
        // of the TestWithParam class:
        //在测试中,使用TestWithParam 类的GetParam()方法访问测试参数:
        T1 n = GetParam();
        std::cout << m_T.a<<"----"<< n.a <

你可能感兴趣的:(Google test)