zoukankan      html  css  js  c++  java
  • 在TeamCity中执行gtest单元测试

    1. 在Visual Studio 2017中新建一个gtest项目 Sample-Test1。这个项目会自动安装“Microsoft.googletest.v140.windesktop.msvcstl.static.rt-dyn”这个nuget包。我们打开nuget管理工具,然后添加一个“teamcity-gtest-streamer”包

     2.在pch.h中添加头文件应用

    #include "gtest/gtest.h"
    #include "teamcity_gtest.h"

    3. 修改test.cpp为以下内容

    #include "pch.h"
    
    TEST(TestCaseName, TestName) {
      EXPECT_EQ(1, 1);
      EXPECT_TRUE(true);
    }
    
    TEST(TestCaseName1, TestName1) {
        EXPECT_EQ(2, 2);
        EXPECT_TRUE(3 == 3);
    }
    TEST(TestCaseName1, TestName2) {
        EXPECT_EQ(2, 3);
        EXPECT_TRUE(3 == 3);
    }
    
    int main(int argc, char** argv) {
        ::testing::InitGoogleTest(&argc, argv);
    
        //if (jetbrains::teamcity::underTeamcity()) {
        //    ::testing::TestEventListeners& listeners = ::testing::UnitTest::GetInstance()->listeners();
        //    // Add unique flowId parameter if you want to run test processes in parallel
        //    // See http://confluence.jetbrains.net/display/TCD6/Build+Script+Interaction+with+TeamCity#BuildScriptInteractionwithTeamCity-MessageFlowId
        //    listeners.Append(new jetbrains::teamcity::TeamcityGoogleTestEventListener());
        //}
    
        //if (jetbrains::teamcity::underTeamcity()) {
            ::testing::TestEventListeners& listeners = ::testing::UnitTest::GetInstance()->listeners();
            // Add unique flowId parameter if you want to run test processes in parallel
            // See http://confluence.jetbrains.net/display/TCD6/Build+Script+Interaction+with+TeamCity#BuildScriptInteractionwithTeamCity-MessageFlowId
            listeners.Append(new GTest::TeamCityAdapter());
        //}
    
        return RUN_ALL_TESTS();
    }

    4. 在teamcity中新增一个项目,项目的配置如下

    5. 等待运行结果,如下图所示,两个执行成功,一个执行失败

    一起都已经完成。后续集成更多功能和单元测试即可。

     具体代码可以参照 https://github.com/jhy871167495/teamcity_gtest_demo

    相关参考:teamcity-gtest-streamer bitbucket地址

    https://github.com/JetBrains/teamcity-cpp

  • 相关阅读:
    openlayers跨域设置后出现http status 500错误
    myeclipse 2014 闪退问题解决
    html跨域获取数据
    centos的nginx支持ssl
    Hadoop学习笔记---HDFS
    Nginx Web服务器配置
    用ReentrantLock和Condition实现线程间通信
    Android绘图机制和处理技巧
    自定义ViewPagerIndicator-视图指示器
    Docker学习笔记
  • 原文地址:https://www.cnblogs.com/Martianhh/p/10078429.html
Copyright © 2011-2022 走看看