JUnit assertEquals更改字符串 [英] JUnit assertEquals Changes String

查看:171
本文介绍了JUnit assertEquals更改字符串的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个JUnit测试,如下所示:

I have a JUnit test that is as follows:

@Test
public void testToDatabaseString() {
  DateConvertor convertor = new DateConvertor();
  Date date = convertor.convert("20/07/1984:00:00:00:00");
  String convertedDate = convertor.toDatabaseString(date);

  assertEquals("to_date('20/07/1984:00:00:00:00', 'DD/MM/YYYY HH24:MI:SS')",convertedDate);
}

测试失败说明:

org.junit.ComparisonFailure: expected:<to_date('20/07/1984[00:]00:00:00', 'DD/MM/YY...> but was:<to_date('20/07/1984[ ]00:00:00', 'DD/MM/YY...>

特别感兴趣的是预期值为:

Of particular interest is why the expected value is:

to_date('20 / 07/1984 [00:] 00:00:00',等......

当我的测试中的字符串字面清楚时:

when my string literal in the test is clearly:

to_date('20 / 07/1984:00:00:00:00',等..

有人能解释一下吗?为什么要添加[00:]?感谢帮助。

Can anyone explain this? Why does it add "[00:]"? Appreciate the help.

推荐答案

方括号强调预期字符串与实际字符串之间的差异。

The square brackets are emphasising the difference between the expected string and the actual string.

JUnit将方括号放在:00 周围,以强调这是预期字符串中的内容而不是实际字符串中的内容。由于同样的原因,它们是实际字符串中空格的方括号。

JUnit put the square brackets around the :00 to emphasise that that is what's in the expected string and not in the actual string. There are square brackets around the space in the actual string for the same reason.

这篇关于JUnit assertEquals更改字符串的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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