문제

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