googletest

当年要是这样搞,我的C++也不至于这样

你离开我真会死。 提交于 2021-02-15 01:58:47
C++一直被称作永不过时的开发语言,比如游戏、服务器、人工智能等领域都必须用到C++! 虽然网上有很多教程和资料,但仍有很多人说C++难学,究其原因是 没有找到正确的学习方法 ! GoogleTest框架一直广泛应用于C/C++项目测试 ,是一个非常重要的测试软件。 它的开发过程几乎 覆盖C++核心知识和C++项目开发经常遇到的问题 ,是新手锻炼C++开发能力最好的项目之一! 因此,今天就给大家分享1个《 C++开发实战3天特训营 》! 这个训练营,老师会带你使用C++实现快速排序算法, 深刻理解C++编程思想 。 而且会重点带你经历,从GoogleTest实现原理到构建项目的全流程,让你能够从0到1独立开发一个C++项目, 快速提升项目能力 ! 特训营老师胡船长是我一直非常敬重的大神,他早在10年前就获得了 ACM亚洲区金牌 ,并 2次晋级全球总决赛 。 此后任职 百度知识图谱部 ,推动开发百度NLP推理引擎开发。 他也会从自己在百度多年的面试角度出发, 讲解大厂面试的核心关键点 ,教你如何准备大厂面试,拿下高薪offer! 特训营原价 599 元,靠着关系搞到 100 个免费名额, 0 元即可入学!只要你是统招本科及以上学历,就可以抢占! 长按3秒 即可扫码 你现在长按识别上方二维码或点击阅读原文,即可直接抢占 0 元免费名额。 本文分享自微信公众号 - 程序员cxuan

Stub system function in google test

£可爱£侵袭症+ 提交于 2021-02-10 17:35:46
问题 I am trying to use Google Test to test C code but I am encounter some problem related to write stub for system functions like: fopen,fclose,fread,fwrite, memcpy,memset,stat,...I don't known how to stub them correctly to cover all branchs in function that need to be tested. Example , I have a function, how to test it by stub fopen, fclose, fwrite, fread? Only Stub, not Mock. #include <stdio.h> #include <stdlib.h> int main(){ FILE *f; //initialize the arr1 with values int arr1[5]={1,2,3,4,5};

CMake - Undefined Reference

不问归期 提交于 2021-02-10 06:42:46
问题 I am trying to include gtest to my project. The problem is that I get a undefined reference error in the GTest. I am trying to test the Node class in Gtest. Inside the constructor of the Node I am using the Class Logger. Although I have added the library logger to the gtest-target I still the undefined reference error regarding to the Logger.... My guess CMake does no look for nested classes that are used inside Node. only Node itself. Temperoy fix If I use the Logger in the gtest-node.cpp it

Exclude the header files coverage while doing the unitests for .cpp files using lcov

我与影子孤独终老i 提交于 2021-02-09 07:35:45
问题 I have generated the html code coverage for unittest. The problem is that it generates the code coverage for everything that is defined in the include preprocessor. The codecoverage for the unittest is inside the unitTest link of the code coverage report. I only need the unitTest I also remove everything else and keep the gcda and gcno files of the test file before generating the code coverage but it still doesnot help. The code that does this is : find obj/ ! -name '*_unittests*' -type f

Exclude the header files coverage while doing the unitests for .cpp files using lcov

喜夏-厌秋 提交于 2021-02-09 07:31:37
问题 I have generated the html code coverage for unittest. The problem is that it generates the code coverage for everything that is defined in the include preprocessor. The codecoverage for the unittest is inside the unitTest link of the code coverage report. I only need the unitTest I also remove everything else and keep the gcda and gcno files of the test file before generating the code coverage but it still doesnot help. The code that does this is : find obj/ ! -name '*_unittests*' -type f

C++ unit test - Test class with throwed error in constructor

半腔热情 提交于 2021-02-08 10:01:52
问题 I have a problem with testing class with member variable which is not dependent on me. I mean the class contain a variable that is include from other file. And this class throwing error in constructor(no matter why). And then I have a function that uses this variable. So how should I test this class? // ** classForMe.h can't modify ** class ClassForMe { public: ClassForMe(){ // not relevant what should be here but throw error in this case throw std::runtime_error(""); } int getData()const

GTest, parameterize test case only

淺唱寂寞╮ 提交于 2021-02-07 09:56:54
问题 I want to apply a parameterized test and have the following fixture: class MyTest: public ::testing::TestWithParam<float> {...}; I want to set up two parameterized test cases, one where small parameters fail, but larger succeed. TEST_P(MyTest, smallParamsFail) { auto param = GetParam(); EXPECT_EQ(true, param<1); } TEST_P(MyTest, largeParamsSucceed) { auto param = GetParam(); EXPECT_EQ(true, param>1); } I want now to start testcase smallParamsFail with values smaller one, the other with values

Command-line options to force googletest to run in single thread

ⅰ亾dé卋堺 提交于 2021-02-07 06:45:06
问题 I have a suite of unit tests that is managed by googletest. These tests are run in multiple threads by default, even when I use --gtest_filter=foo.test so that it only runs a single test. This is causing ambiguity about the cause of a bug I'm trying to hammer out. How can multithreaded testing be turned off in googletest? 回答1: There's no commandline switch for single/multi-threading. libgtest is built either single-threading or multi-threading. To make it single-threading, build gtest with .

How do you mock and test the same function in C/C++ with FFF and Google Test?

|▌冷眼眸甩不掉的悲伤 提交于 2021-02-05 11:35:13
问题 I am exploring TDD (Test Driven Development) to test the code that I am writing in C and C++. I have chosen to use Google Test as the unit test framework. I have chosen to use FFF as the mocking framework. I have written a few tests and run them and it works great. But I have come across an issue that I have not been able to find any reference to online and I was hoping the community could help me (and this would help others as well). The issue I have is that I would like to write a test for

在Codeblocks下配置GoogleTest单元测试工具

纵然是瞬间 提交于 2021-01-31 00:31:37
开发工具 我和我的组员的都是使用的是大一老师推荐的codeblocks,所以,就愉快的决定了工具统一为codeblocks,语言C++。 测试单元 老师推荐的是JUnit和VSTS工具,但同学们从大一到现在最熟悉的还是codeblocks编程软件。既然的其他编程软件能加载测试工具,我想,codeblocks也行,百度后发现googleTest支持codeblocks(我就说会有的。。)。那么接下来,是具体的配置过程。 工具下载 1. googleTest官网上最新版为1.8.0版本的,但我试了并不能成功Build,所以我这里给出1.7版本的。这里还需要下载cMake用来生成cbp文件让codeBlocks识别。 工具下载地址: https://pan.baidu.com/s/1uSu_TioPFOal6MYdM5Zp5A 2.分别解压两个文件后,进入cmake文件夹的bin下,运行cmake-gui。 在“where is the source code”中选择解压后的googletest文件路径,如我的路径为 C:/Users/Administrator/Desktop/googletest-release-1.7.0/googletest-release-1.7.0 , 然后在“where to build the binaries ”可选择在解压路径下新建的一个文件夹路径,如