Eclipse:infinitest 与 JUnit:字符编码
我在 Eclipse 中使用Infinist,并且在与 JUnit 相关时出现了一个奇怪的现象。
我有使用 org.apache.http.HttpResponse.getEntity() 和 org.apache.http.entity.StringEntity 的代码。 JUnit 测试如下所示:
@Test
public void convertEncodedContentToString() throws UnsupportedEncodingException {
HttpResponse httpResponseMock = Mockito.mock(HttpResponse.class);
Mockito.when(httpResponseMock.getEntity()).thenReturn(new StringEntity("huiäöüß@€", HTTP.UTF_8));
Assert.assertEquals("huiäöüß@€", parser.convertContentToString(httpResponseMock));
}
所有源文件都以 UTF-8 存储。
如果我让 JUnit 执行这个方法,它就可以正常工作。
然而,如果Infinist运行这个测试,它会抱怨断言失败。
ComparisonFailure (expected:<hui[äöüß@€]> but was:<hui[äöüß@€]>) in ResponseBodyParserFactoryTest.convertEncodedContentToString
显然存在字符编码问题。
由于Infinist几乎没有任何选择,我不知道如何帮助Infinist正确运行这个测试。有人可以帮我吗?
I'm using infinitest in Eclipse and I have a strange phenomenon in connection with JUnit.
I have code that uses org.apache.http.HttpResponse.getEntity()
and org.apache.http.entity.StringEntity
. The JUnit test looks like this:
@Test
public void convertEncodedContentToString() throws UnsupportedEncodingException {
HttpResponse httpResponseMock = Mockito.mock(HttpResponse.class);
Mockito.when(httpResponseMock.getEntity()).thenReturn(new StringEntity("huiäöüß@€", HTTP.UTF_8));
Assert.assertEquals("huiäöüß@€", parser.convertContentToString(httpResponseMock));
}
All source files are stored in UTF-8.
If I let JUnit execute this method, it works fine.
However, if infinitest runs this test it complains that the assertion fails.
ComparisonFailure (expected:<hui[äöüß@€]> but was:<hui[äöüß@€]>) in ResponseBodyParserFactoryTest.convertEncodedContentToString
Obviously there is a character encoding problem.
As infinitest has close to no options I have no idea how to help infinitest to run this test properly. Can anyone please help me out here?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您需要告诉Infinist,它必须使用UTF-8 字符集来运行测试。
只需在 Eclipse 项目中添加一个文件:“infinitest.args”。
在此文件中,添加以下内容:
因此,inifinitest 将使用 UTF-8
用户指南: http:// /infinitest.github.com/doc/user_guide.html 特别是“设置 JVM 选项”部分
You need to say to infinitest that it must use the UTF-8 charset to run the tests.
Just add a file in your Eclipse project: "infinitest.args".
In this file, add the following:
And so, inifinitest will use UTF-8
User guide: http://infinitest.github.com/doc/user_guide.html specifically the 'Setting JVM Options' section