自定义实际/预期的“值" Google Test失败输出消息中的字符串 [英] Customise actual/expected "Value of" string in Google Test failure output messages

查看:78
本文介绍了自定义实际/预期的“值" Google Test失败输出消息中的字符串的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我从 Google测试单元测试获得以下输出:

I have the following output from a Google Test unit test:

UnitTests.cc:56: Failure
Value of: LineSegment2i(Vector2i(-10,0), Vector2i(-10,10)).toLine()
  Actual: 24-byte object <00-00 00-00 00-00 24-C0 00-00 00-00 00-00 00-00 00-00 2F-2B FF-7F 00-00>
Expected: Line(10, 3.14159265358979323846)
Which is: 24-byte object <00-00 00-00 00-00 24-40 18-2D 44-54 FB-21 09-40 00-00 64-00 00-00 00-00>
[  FAILED  ] LineSegmentTests.toLine (1 ms)

该十六进制输出字符串不是很有用.我可以在Line类中添加一些东西(对于它来说,相等性测试失败),以便在这种情况下提供更多有用的错误?

That hexadecimal output string isn't very useful. Is there something I can add to the Line class (for which an equality test is failing) to provide more helpful errors in such cases?

有问题的类已将<<运算符重写为成员函数:

The class in question has overridden the << operator as a member function:

std::ostream& operator<<(std::ostream& stream) const
{
  return stream << "Line (radius=" << d_radius << " theta=" << d_theta << ")";
}

您可以看到这适用于"Expected"行,但不适用于"Actual"行.显示的测试来自TEST宏的参数.

推荐答案

要打印自定义类型,您可以教" Google测试如何打印您的自定义类型,如

In order to print custom types you could "teach" Google Test how to print your custom types which as described in the section Teaching Google Test How to Print Your Values.

这篇关于自定义实际/预期的“值" Google Test失败输出消息中的字符串的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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