googletest

Boost Test Vs Google Test Framework

杀马特。学长 韩版系。学妹 提交于 2019-12-20 08:24:24
问题 I am new to Unit Testing world, basically I am c++ developer working on a large product for almost 3 years, and now I've decided to perform automated unit testing of my code. For this I do lot of research on the internet and came across many tools and frameworks and finally chose the following two: 1) Boost Test Libraries 2) Google Test Framework for c++ Now I am confused as to which to choose from those. If someone uses any of the above then please share your experience. 回答1: The below SO

How to send custom message in Google C++ Testing Framework?

我是研究僧i 提交于 2019-12-20 08:02:28
问题 I use Google C++ Testing Framework for unit testing of my code. I use Eclipse CDT with C++ Unit testing module for output analysis. Previously I used CppUnit it has macros family CPPUNIT*_MESSAGE that could be called like this: CPPUNIT_ASSERT_EQUAL_MESSAGE("message",EXPECTED_VALUE,ACTUAL_VALUE) And allows to send custom messages to test output. Is there a way to include some custom text in google test output? (Preferably the way that could include message to data that is read by existing

Googletest Eclipse C++ : How to have both test and production executable?

ぐ巨炮叔叔 提交于 2019-12-20 05:48:12
问题 I have a basic question regarding Googletest in Eclipse. I am using the test-runner plug in to run the Googletests. But I need to specify a binary which runs my unit tests (of course that makes sense.) The problem is that in my project I now have two main functions, one to run the actual program and one int main(int argc, char** argv) { ::testing::InitGoogleTest(&argc, argv); return RUN_ALL_TESTS(); } to run the google tests. Each time I want to run one I comment the other out, which of

unit test in eclipse g++

一世执手 提交于 2019-12-20 04:12:58
问题 I am using Eclipse to develop some projects and implement unit test by using google test. everything was fine this morning. I can build project and run unit tests. however, after i commit the local changes and then pull the codes from repository using git tortoise, the unit tests stopped working any more. I still can build the project. I got msg: Unknown error during parsing Google Test module output: unexpected test module output this is the msg in the console window: The target endianness

Convenient method in GoogleTest for a double comparison of not equal?

那年仲夏 提交于 2019-12-19 17:35:05
问题 I'm looking for something similar to the ASSERT_EQ / ASSERT_NE for ASSERT_DOUBLE_EQ. Maybe I'm missing an easy way of doing this without having a ASSERT_DOUBLE_NE? 回答1: You can use the companion mocking framework Google Mock. It has a powerful library of matchers (a la Hamcrest), which you can use with the EXPECT_THAT/ASSERT_THAT macros: EXPECT_THAT(value, FloatEq(1)); EXPECT_THAT(another_value, Not(DoubleEq(3.14))); 回答2: It looks like you're out of luck. However, you could add one yourself.

Mock non-virtual method giving compilation error

回眸只為那壹抹淺笑 提交于 2019-12-19 10:09:20
问题 I need to write the gtest to test some existing code that has a non-virtual method, hence I am testing using the below source, but I am getting the compilation error package/web/webscr/sample_template_class3.cpp: In function âint main()â: package/web/webscr/sample_template_class3.cpp:64: error: âclass Templatemyclassâ has no member named âgmock_displayâ sample_template_class3.cpp #include <iostream> #include <gtest/gtest.h> #include <gmock/gmock.h> using namespace std; template < class

GTest's output has no colors when built with cmake+ninja and executed automatically

馋奶兔 提交于 2019-12-19 07:15:42
问题 I'm trying to configure CMake and ninja as a build system for my project. Except the app itself I have an extra executable for unit tests powered by gtest. I thought it would be nice to have them executed automatically whenever they are built. Here's how I made it: ├── build └── source ├── CMakeLists.txt ├── main.cc └── ut ├── CMakeLists.txt ├── gtest │ ├── ... └── ut.cc source/CMakeLists.txt... cmake_minimum_required (VERSION 2.6) project (trial) add_subdirectory(ut) add_executable(trial

Verifying exception messages with GoogleTest

一个人想着一个人 提交于 2019-12-19 06:04:33
问题 Is it possible to verify the message thrown by an exception? Currently one can do: ASSERT_THROW(statement, exception_type) which is all fine and good but no where can I find a way to test e.what() is really what I am looking for. Is this not possible via google test? 回答1: Something like the following will work. Just catch the exception somehow and then do EXPECT_STREQ on the what() call: #include "gtest/gtest.h" #include <exception> class myexception: public std::exception { virtual const

Separate test cases across multiple files in google test

一个人想着一个人 提交于 2019-12-18 18:37:28
问题 I'm new in google test C++ framework. It's quite easy to use but I'm wondering how to separate the cases into multiple test files. What is the best way? Include the .cpp files directly is an option. Using a header seems that does nothing... Any help is welcome 回答1: Create one file that contains just the main to run the tests. // AllTests.cpp #include "gtest/gtest.h" int main(int argc, char **argv) { testing::InitGoogleTest(&argc, argv); return RUN_ALL_TESTS(); } Then put the tests into other

单元测试C代码[关闭]

十年热恋 提交于 2019-12-18 13:45:22
【推荐】2019 Java 开发者跳槽指南.pdf(吐血整理) >>> 今年夏天,我用直接C编写了一个嵌入式系统。这是我工作的公司接管的现有项目。 我已经习惯于使用JUnit在Java中编写单元测试,但是对于为现有代码(需要重构)编写单元测试的最佳方法以及添加到系统中的新代码感到茫然。 是否有任何项目使单元测试普通C代码与使用JUnit进行单元测试Java代码一样简单? 任何专门针对嵌入式开发(交叉编译到arm-linux平台)的见解都将非常感激。 #1楼 我个人喜欢 Google Test框架 。 测试C代码的真正困难在于打破了对外部模块的依赖性,因此您可以将代码单独隔离。 当您尝试围绕遗留代码进行测试时,这可能会特别成问题。 在这种情况下,我经常发现自己使用链接器在测试中使用存根函数。 这是人们在谈论“ 接缝 ”时所指的。 在C中,您唯一的选择就是使用预处理器或链接器来模拟您的依赖项。 我的一个C项目中的典型测试套件可能如下所示: #include "myimplementationfile.c" #include <gtest/gtest.h> // Mock out external dependency on mylogger.o void Logger_log(...){} TEST(FactorialTest, Zero) { EXPECT_EQ(1,