Category : googletest

I am using GTEST_SKIP() inside TEST_P() method. I want to skip the test if some condition is true. But for those scenarios, instead of skipping its throwing segmentation fault error. My code is like TEST_P(testfixture, testcase) { if(conditionA == true) { GTEST_SKIP() << "Skip test" ; } ASSERT_EQ(some condition); } It only gives seg fault ..

Read more

How to return multiple mock objects from a mocked factory function which returns std::unique_ptr? Return(ByMove(…)) cannot be used to return multiple times. Trying to work from this answer: https://stackoverflow.com/a/70751684/3545094 I came up with this: class MyType { public: virtual ~MyType() {} }; class MyTypeMock : public MyType {}; class MyFactory { public: virtual ~MyFactory() {} ..

Read more

I am using GTest to unit test an older library with MFC classes and having trouble with GTest converting special characters. For example, this test (which fails intentionally) needs to preserve the bullet char #include "gtest/gtest.h" #include <afx.h> namespace UnitTests { TEST(ThisTest, WillFail) { CString actual = _T("•"); CString expected = _T("ABC"); EXPECT_STREQ(expected, actual); } ..

Read more

How can I return multiple object from a mocked factory returning unique_ptr, when the calls cannot be identified through different input parameters to the called function? I’m doing this: EXPECT_CALL(MyFactoryMock, create()) .WillRepeatedly(Return(ByMove(std::make_unique<MyObjectTypeMock>()))); And run-time error is: [ FATAL ] /…/tools/googletest/1.8.0-57/include/gmock/gmock-actions.h:604:: Condition !performed_ failed. A ByMove() action should only be performed once. Doing the same thing ..

Read more