Frage

I am using Gtest for unit testing. There are some methods which return an object. Example is shown below

Class ToTest{
public:
object& method(){
object* obj = new object();
return obj;
}
}

"ToTest" is the class that is to be tested. It has a method which returns an object "obj". How can i validate this object using Gtest ?

War es hilfreich?

Lösung

So, you want to test a singleton. As you see, there is almost nothing to test there. You can call that method, and that is it. There is nothing to validate, except there are no leaks (by executing the unit test program using valgrind or similar tool).

class ToTestTest : public testing::Test
{
public:
    ToTestTest()
    {
    }
    ~ToTestTest()
    {
    }

    ToTest obj;
};

TEST_F( ToTestTest, method )
{
    obj.method();
}
Lizenziert unter: CC-BY-SA mit Zuschreibung
Nicht verbunden mit StackOverflow
scroll top