15

I'm trying to get a working googletest test that compares two vectors. For this I'm using google mock with its matchers but I get a C3861 error saying "ContainerEq identifier not found" and also C2512 saying "testing::AssertionResult has not a proper default constructor available". Why?

TEST(MyTestSuite, MyTest)
{
    std::vector<int> test1;
    std::vector<int> test2;

    ...

    EXPECT_THAT(test1, ContainerEq(test2));
}
1
  • This question has a recent correct answer by @phetdam #phetdam yesterday

2 Answers 2

36

You're just missing gtest's testing namespace qualifier:

EXPECT_THAT(test1, ::testing::ContainerEq(test2));
0
1

Since std::vector does define operator==, why not just use EXPECT_EQ? Ex.

#include <vector>

#include <gtest/gtest.h>

namespace {

TEST(MyTestSuite, MyTest)
{
  std::vector<double> a = {1, 2};
  std::vector<double> b = {1, 2};
  EXPECT_EQ(a, b);
}

}  // namespace

This works just fine. Although I mostly use C++17, std::vector definitely predates C++11.

For any of your own custom Container types, define your own operator==.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.