googletest

gtest.h file not found googletest xcode 7.0

为君一笑 提交于 2020-01-01 04:55:10
问题 I'm trying to setup google testing framework for my c++ project following this guide in xcode 7.0 I got to the last step Build and Go but after hours of searching online I can't get my test project to run. The compiler does not seem to find the headers it needs. main.cpp:9:10: 'gtest/gtest.h' file not found. The source is: #include "gtest/gtest.h" #include "calc.hpp" int main(int argc, const char * argv[]) { return 0; } I also tried #include <gtest/gtest.h> With same result. 回答1: Sometimes,

How to pretty-print QString with GoogleTest framework?

青春壹個敷衍的年華 提交于 2020-01-01 04:38:26
问题 I am using the GoogleTest (GTest) framework in conjunction with a Qt5 application. Whenever a test fails using a QString argument, the framework tries to print all the involved values. However, it cannot automatically handle foreign types (Qt5's QString in this case). QString test = "Test"; ASSERT_EQ(test, "Value"); How can I get GoogleTest to pretty print QStrings automatically (= without having to manually convert them each time)? 回答1: The GoogleTest Guide explains how you can in general

How to compile googletest on windows using mingw with msys?

你。 提交于 2019-12-30 00:05:32
问题 My need is simple. I have to compile and use googletest on windows using MinGW with msys. Has anyone some experience doing this? Thanks for answers. 回答1: It took me some time but I figured it out. Here is the guide for anyone who face the same problem. To be able to compile GoogleTest on Windows follow this instructions: I assume you have MinGW with MSYS istalled. Download and install CMake from the official site http://www.cmake.org/. Use the Win32 installer version. Once you have completed

What are Google Test, Death Tests

倾然丶 夕夏残阳落幕 提交于 2019-12-28 13:43:13
问题 I saw the documentation of that feature is seem pretty major since it's in Google Test overview features and detailed in: https://github.com/google/googletest/blob/master/googletest/docs/advanced.md#death-tests They look like standard assert() but they're part of Google Test, so a xUnit testing framework. Therefore, I wonder what the real usage or advantage of using those death tests are. 回答1: The assertion is there to confirm that a function would bring about program termination if it were

Can I copy a google mock object after setting expectations?

笑着哭i 提交于 2019-12-24 11:27:16
问题 I want to add a utility function in my test fixture class that will return a mock with particular expectations/actions set. E.g.: class MockListener: public Listener { // Google mock method. }; class MyTest: public testing::Test { public: MockListener getSpecialListener() { MockListener special; EXPECT_CALL(special, /** Some special behaviour e.g. WillRepeatedly(Invoke( */ ); return special; } }; TEST_F(MyTest, MyTestUsingSpecialListener) { MockListener special = getSpecialListener(); // Do

Google Mock: Mock private variable member that is instantiated in target class's constructor

不问归期 提交于 2019-12-24 08:33:51
问题 My question is the same as Mockito: Mock private field initialization but for Google Mock framework. In a nutshell: class Target { private: Person person = new Person(); public: void testMethod() { person.someMethod(); } }; How can I mock the person instance while making unit tests for Target class? 回答1: A non-answer here: simply don't do it this way. Your problem is the call to new here. Thing is: that makes testing hard, and it also creates a very tight coupling between the Target and the

Linking GoogleTest and CodeBlocks

大憨熊 提交于 2019-12-24 07:38:12
问题 I'm afraid that it is a basic problem, I might have found the answer with other IDEs but not with CodeBlocks =( I try to use GoogleTest. I downloaded the project, built it with cmake -G "CodeBlocks - Unix Makefiles" (I'm on Ubuntu) That gave me the libgtest.a and libgtest_main.a files that I transfered in /usr/lib And I think my lacks are on the last step : linking GoogleTest and CodeBlocks. Some tutorials told to add the "-lgtest" linker option, I tried many things but it's all the same :

Linking against GTest fails

不羁的心 提交于 2019-12-24 07:31:05
问题 I have the following CMakeLists.txt : cmake_minimum_required(VERSION 3.15) set(CMAKE_CXX_STANDARD 17) # adding library set(ST_SRC simple_tree.cpp) add_library(st ${ST_SRC}) target_include_directories(st PUBLIC ${PROJECT_SOURCE_DIR}/include/data_structures/simple_tree/) # adding googletest set(GOOGLETEST_PATH ~/local/googletest) set(GTEST_INCLUDE_DIR ~/local/include/) set(GTEST_LIBRARY ~/local/lib/) set(GTEST_MAIN_LIBRARY ~/local/lib/) find_package(GTest REQUIRED) # adding tests set(TEST

EXPECT_CALL without mock in Google Test

人盡茶涼 提交于 2019-12-24 02:10:04
问题 Is there any way to test a function call via GoogleTest for c++ without creating mock object, e.g. we have the following production code: if (a) method(x); I would like to test whether the method will be called in the case a is True and a is False. I would like to construct a test that does exactly the same what Google Test's EXPECT_CALL does, but EXPECT_CALL works only with the mock object's method. In my case I would prefer not to use a mock (there is no need to create any object). 回答1: As

Does pytest have anything like google test's non-fatal EXPECT_* behavior?

假如想象 提交于 2019-12-24 01:47:22
问题 I'm more familiar with the google test framework and know about the primary behavior pair they support about ASSERT_* vs EXPECT_* which are the fatal and non-fatal assert modes. From the documentation: The assertions come in pairs that test the same thing but have different effects on the current function. ASSERT_* versions generate fatal failures when they fail, and abort the current function. EXPECT_* versions generate nonfatal failures, which don't abort the current function. Usually