Testing for sameness

67 Views Asked by At
BOOST_AUTO_TEST_CASE(testing_sameness) {
    Dependency dep;
    T foo(dep);
    BOOST_CHECK_EQUAL(dep, foo.dep());
}

In a test like this, how to write the last line in order to test that the dep() method really returns the same object as injected over the constructor?

The underlying class should not implement additional methods like overloading the == operator.

Ideally, I would like to simply compare the addresses of both objects. The method is declared as:

Dependency dep() : const;

Writing this test is more for educational purposes, I wouldn't test getters like that in practice.

0

There are 0 best solutions below