Category : unit-testing

I am a beginner for Gtest and facing segmentation fault when accessing a class variable inside TEST_F. Below is the snippet of my code, kindly help in pointing the reason behind this behavior. main.cpp #include <Foo.h> #include "gtest/gtest.h" int main(int argc, char* argv[]) { InitalRegister(); ::testing::InitGoogleTest(&argc, argv); int rc = RUN_ALL_TESTS(); return rc; } Foo.h ..

Read more

I configured GoogleTest via CMake and the extra arguments added to the projects are ignored by VS2019 Test Explorer. I’m guessing the reason is that Test Explorer has got its own settings in VS2019, and those settings appear among the arguments of the executable, but not the ones I provided. When I’m running CTest from ..

Read more

I somehow extended the gmock test case from donsoft.io’s example, and made it as follows: coinflipper/ ├── BUILD ├── WORKSPACE ├── coinflipper.cc ├── coinflipper.h ├── rng.cc └── rng.h Well, instead put the Rng class as a parameter of the constructor of the CoinFlipper, I made it initialized inside the CoinFlipper::flipCoin() method. I was wondering how ..

Read more

I was trying to make a minimal gmock test case from donsoft.io’s example The file structure is simple: my_workspace/ ├── BUILD ├── WORKSPACE ├── coinflipper.cc ├── coinflipper.h ├── mockrng.cc ├── mockrng.h └── rng.h I got this error while trying to compile by $ bazel test –test_output=all //:mockrng $ bazel test –test_output=all //:mockrng INFO: Analyzed target ..

Read more

I need to test some code, and methods accepts pointers to objects. As I want to write many tests, simplified my tests looks like this bool addPoint(Point* point); EXPECT_TRUE(addPoint(&Point(0, 0, 0))); EXPECT_TRUE(addPoint(&Point(-10, 0, 0))); EXPECT_TRUE(addPoint(&Point(0, -10, 0))); //and so on It works fine. I know that taking address of the temporary variable isn’t a good ..

Read more

I’m trying to test object behavior, but my test always passes even if the mock method hasn’t been called. The case is simple. There are few io-blocks. Each block does data processing and pass them to the next block. The code is presented bellow. GtestCheck.h #include <memory> #include <string> #include <gtest/gtest.h> #include <gmock/gmock.h> using ::testing::NiceMock; ..

Read more