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));
}
DerKasper
  • 167
  • 2
  • 11
Stefano
  • 3,213
  • 9
  • 60
  • 101

2 Answers2

36

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

EXPECT_THAT(test1, ::testing::ContainerEq(test2));
Fraser
  • 74,704
  • 20
  • 238
  • 215
0

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==.

phetdam
  • 96
  • 1
  • 8