googletest

What is the proper way to configure googletest with Xcode 4?

不想你离开。 提交于 2019-12-24 00:47:16
问题 I am following the instructions located at https://github.com/google/googletest/blob/master/googletest/docs/XcodeGuide.md to set up googletest to work with Xcode. However, these instructions seem to be written for Xcode 3. Many things that this article mentions have changed in Xcode 4. What is the proper way to get google test to work with Xcode 4? 回答1: I suggest using the open source xcode-googletest in order to integrate also with Xcode Test Framework (XCTest) 回答2: Follow the instructions

How to unit test the std::bind function using gtest?

家住魔仙堡 提交于 2019-12-23 17:33:54
问题 I am trying to write unittest cases for some of the cpp files in my project. The scenario here is: I have a cpp file with only one public method defined and in turn which calls private methods. Here the private methods are called in the public method as a callback method. How do I test the private methods here. I will be doing the mocking for Callback pointer and I am not sure how to call the private method. Please give me some suggestions how to call the private methods in this scenario

Choose random number distribution at compile time

匆匆过客 提交于 2019-12-23 15:38:51
问题 I am writing tests using the TYPED_TEST feature of google tests, which allows me to generalize a test to multiple types. I am testing a class template for the types int and double . In a test, I would need to generate random numbers. To do so, I have tried using the std::uniform_int_distribution<T> and the std::uniform_real_distribution<T> but have ran into static asserts. As the names indicate, std::uniform_int_distribution<T> checks if T is an integral type and std::uniform_real

GTest fixture when constructor takes parameters?

[亡魂溺海] 提交于 2019-12-23 12:19:05
问题 I have a simple example class. It has one data member, which is a std::vector of pointers to armadillo matrices. the constructor takes such a vector as the only argument. here's file TClass.cpp : #include <armadillo> #include <vector> class TClass { private: std::vector<arma::mat * > mats; public: TClass(std::vector<arma::mat * > m_); arma::mat * GetM( int which ){ return( mats.at(which) );}; }; TClass::TClass(std::vector<arma::mat * > m_){ mats = m_; } I want to construct a GTest fixture to

Testing with GTest and GMock: shared vs. static libraries

南楼画角 提交于 2019-12-23 10:00:06
问题 I think this question may violate some of the Q&A standards for the site, as the answer(s) I may receive could be regarded as opinion-driven. Nevertheless, here it goes... Suppose we're working on a C++ project, using CMake to drive the build/testing/packaging process, and GTest and GMock for testing. Further suppose the structure of our project looks like this: cool_project | |-- source | | | |-- module_foo | | | | | |-- (bunch of source files) | | | |-- module_bar | | | |-- (yet more source

How to expect program exit in gtest?

假装没事ソ 提交于 2019-12-23 09:48:32
问题 I'm testing some code that uses CHECK from glog and I'd like to test that this check fails in certain scenarios. My code looks like: void MyClass::foo() { // stuff... // It's actually important that the binary gets aborted if this flag is false CHECK(some_flag) << "flag must be true"; // more stuff... } I've done some research into gtest and how I might be able to test for this. I found EXPECT_FATAL_FALIURE , EXPECT_NONFATAL_FAILURE , and HAS_FATAL_FAILURE but I haven't managed to figure out

Customise actual/expected “Value of” string in Google Test failure output messages

别来无恙 提交于 2019-12-23 07:26:37
问题 I have the following output from a Google Test unit test: UnitTests.cc:56: Failure Value of: LineSegment2i(Vector2i(-10,0), Vector2i(-10,10)).toLine() Actual: 24-byte object <00-00 00-00 00-00 24-C0 00-00 00-00 00-00 00-00 00-00 2F-2B FF-7F 00-00> Expected: Line(10, 3.14159265358979323846) Which is: 24-byte object <00-00 00-00 00-00 24-40 18-2D 44-54 FB-21 09-40 00-00 64-00 00-00 00-00> [ FAILED ] LineSegmentTests.toLine (1 ms) That hexadecimal output string isn't very useful. Is there

Using googlemock with fake impls of non-virtual functions

倾然丶 夕夏残阳落幕 提交于 2019-12-22 16:35:42
问题 I've got legacy code with some unit tests based on googlemock framework. While I was trying to extend the unit tests with some new scenarios I met the following problem: class D { public: void pubMethod1(); int pubMethod2(); // There are pretty much non-virtual methods, both public and private ... protected: uint method3(); void method4(); ... // Some class members are here }; class SUT { public: ... protected: D _dep; }; The SUT class (software under test) should be tested, its

Can googlemock mock method calls from within other method calls of the same class?

ぐ巨炮叔叔 提交于 2019-12-22 11:36:41
问题 Is it possible to mock method calls from within other method calls of the same class? I am new to C++ (primarily a C developer) and very new to googlemock and Google Test so forgive me if this is answered elsewhere and I didn't understand the answer! Below is a simple example that should explain what I want to do. Using the example below, I want to mock ReturnInput , while testing ReturnInputPlus1 . using ::testing::Invoke; using ::testing::_; using ::testing::Return; class MyClass { public:

GoogleTest CMake and Make tests not running

馋奶兔 提交于 2019-12-22 11:09:18
问题 I admit I have a unique situation. We build our application using Make. But my IDE, CLion, uses CMake. So I have tried to set up GoogleTest to run on both (kind of). I can compile my code both ways (using make at the command line and build from my IDE). But from within CLion when I select the test fixture and click the run button, no tests are found and this is what I receive: Running main() from gtest_main.cc [==========] Running 0 tests from 0 test cases. [==========] 0 tests from 0 test