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 ?

有帮助吗?

解决方案

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();
}
许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top