Get google test exception throw message [duplicate]

三世轮回 提交于 2019-12-06 22:25:52

问题


I am using google Test framework for my project. I am throwing exception from the code as:

throw DerivedClassException("message");  

and in the test frame using as:

ASSERT_THROW(commond(), DerivedClassException);  

I want to get message with what() API. Any way to get exact exception message of the exception.


回答1:


The only way to check the thrown exception is to catch it in the test :

void test_foo( MyTest, TestException )
{
  try
  {
    functionThatThrowsException();
    FAIL();
  }
  catch( const DerivedClassException& err )
  {
    // check exception
    ASSERT_STREQ( "error message", err.what() );
  }
}


来源:https://stackoverflow.com/questions/29506426/get-google-test-exception-throw-message

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!