googletest

Linker error - linking two “application” type projects in order to use Google Test

北城以北 提交于 2019-12-08 02:31:47
问题 I am trying to test a function with Google Test. It seems that everything is set up correctly, and it builds and executes fine without gtest... (There is a bit of complexity in the code, so I cannot list all the source files here, but without adding gtest, the files are linking properly, and running as they should). It is an application type project. It has a number of library dependencies... irrelevant. The test project is added as a separate project to the solution. It has the tested

Where do I place the Unit Testing source and expose the internal components?

人盡茶涼 提交于 2019-12-07 18:16:07
问题 I am taking over a project that exposes components via ATL. I see two major areas for the unit test to cover with this setup: Testing the internal components (may or may not be exposed via COM) Testing the external exposed components (aka testing the exposed interface) Currently the project has all of its internal components unit tests inside of the solution. They are enabled by a preprocessor flag that compiles it in and executes when you run. From the research I have been doing, it appears

Create gtest value parametrized test for a template class

故事扮演 提交于 2019-12-07 15:34:19
问题 I have a template class of type <size_t N> class Line { ... }; How could I could I create a test for several instances of this class? e.g. Line<1>, Line<2>, ... I have checked the documentation and there are: Value-Parametrized tests, for run-time values Type-Parametrized tests, which allow you to change the typename at compile time. However, I do not find anything to change values at compile-time. 回答1: Googletest has no ready-to-wear solution for generating tests over a template for a set of

Why is Google Test segfaulting?

五迷三道 提交于 2019-12-07 13:42:01
问题 I'm new to Google Test and I'm playing around with the provided examples. My issue is, when I introduce a failure and set GTEST_BREAK_ON_FAILURE=1 (or use the command line option), GTest will segfault. I am considering this example. If I insert something like this into any of the tests, I will start to get the segfault: EXPECT_EQ(8, 2*3); Just to reiterate, that is only when I have also set GTEST_BREAK_ON_FAILURE=1 . I have run from the command line and also with gdb. If that environment

unit test using gtest 1.6 : how to check what is printed out?

做~自己de王妃 提交于 2019-12-07 13:04:51
问题 How do i check a void function that print out sth to the command line? For example: void printFoo() { cout << "Successful" < endl; } and then in the test.cpp i put this test case: TEST(test_printFoo, printFoo) { //what do i write here?? } please explain clearly as i'm new to unit testing and gtest. Thank you 回答1: You will have to change your function to make it testable. The easiest way to do this is to pass in an ostream ( which cout inherits ) to the function, and use a string stream ( also

Why does Google Test/Mock show leaked mock object error by std::unique_ptr?

核能气质少年 提交于 2019-12-07 08:55:25
问题 Let's assume that there is Bar object which uses a Foo object. The ownership is exclusive, so Bar gets Foo as a std::unique_ptr in its constructor. I would like to test Bar with Google Test framework, so I made a following code: using namespace testing; class Foo { public: virtual int F() = 0; }; class Bar { public: Bar(std::unique_ptr<Foo>&& foo) : m_foo(std::move(foo)) { } int B() { return m_foo->F(); } private: std::unique_ptr<Foo> m_foo; }; class MockFoo : public Foo { public: MOCK

Custom EXPECT_NEAR macro in Google Test

拟墨画扇 提交于 2019-12-07 08:17:00
问题 Scope: Using Google Test and OpenCV. I'd like to test that my Vec3f equals another Vec3f . Vec3f is a vector in OpenCV of dimension 3 and type float. The ==-operator is defined, so EXPECT_EQ(Vec3f(), Vec3f()) works. But as they are floats, I'd like to use the EXPECT_NEAR(float a, float b, float delta) macro. What can I do so that I can use it like EXPECT_NEAR(vec_a, vec_b, float delta) ? At the moment I am looping through each element of the vector and doing an EXPECT_NEAR there. This might

Google Mock: why NiceMock does not ignore unexpected calls?

柔情痞子 提交于 2019-12-07 07:56:37
问题 I am using Google Mock 1.7.0 with Google Test 1.7.0. The problem is when I use NiceMock I get test failures because of unexpected mock function call (which should be ignored by NiceMock as per Google Mock documentation). The code looks like this: // Google Mock test #include <gtest/gtest.h> #include <gmock/gmock.h> using ::testing::Return; using ::testing::_; class TestMock { public: TestMock() { ON_CALL(*this, command(_)).WillByDefault(Return("-ERR Not Understood\r\n")); ON_CALL(*this,

CMake generated Xcode project won't compile

别等时光非礼了梦想. 提交于 2019-12-07 03:02:25
I have a C++ project that I develop on Mac. I can build it via the command-line with ninja or gmake without problems but once I generate the Xcode project it fails. The project itself is a static library that is linked to a command line app that runs googletest. The error I get is that when it comes to build the final executable, Xcode says it can't find the static library. Here's my CMakeLists.txt: CMAKE_MINIMUM_REQUIRED(VERSION 2.8) PROJECT(MyProject) SET(CMAKE_VERBOSE_MAKEFILE 0) # set to 1 for verbose Makefile SET(MyProject_VERSION_MAJOR 1) SET(MyProject_VERSION_MINOR 0) SET(CMAKE_BUILD

Get google test exception throw message [duplicate]

三世轮回 提交于 2019-12-06 22:25:52
问题 This question already has an answer here : Verifying exception messages with GoogleTest (1 answer) Closed 4 years ago . I am using google Test framework for my project. I am throwing exception from the code as: throw DerivedClassException("message"); and in the test frame using as: ASSERT_THROW(commond(), DerivedClassException); I want to get message with what() API. Any way to get exact exception message of the exception. 回答1: The only way to check the thrown exception is to catch it in the