获取google测试异常抛出消息 [英] Get google test exception throw message

查看:206
本文介绍了获取google测试异常抛出消息的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在为我的项目使用Google Test框架。我从代码中抛出异常:

  throw DerivedClassException(message); 

并在测试框中使用as:

  ASSERT_THROW(commond(),DerivedClassException); 

我想用获取消息what() API。
任何方式获取异常的确切异常消息。

解决方案

检查抛出的异常的唯一方法是在测试中抓住它:

  void test_foo(MyTest,TestException)
{
try
{
functionThatThrowsException();
FAIL();
}
catch(const DerivedClassException& err)
{
//检查异常
ASSERT_STREQ(error message,err.what());
}
}


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.

解决方案

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() );
  }
}

这篇关于获取google测试异常抛出消息的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆