【发布时间】:2015-05-04 20:17:56
【问题描述】:
我有一个简单的 JUnit 测试,它检查两个文件是否具有相同的内容。它在我的 Unix 笔记本电脑上运行良好。
这里是测试:
boolean response = false;
try {
File got = File.createTempFile("got-", ".csv");
String outputPath = got.getAbsolutePath();
testedObject.createCsvFile(outputPath);
got = new File(outputPath);
String expectedFilePath = getClass().getClassLoader().getResource("expected.csv").getFile();
File expected = new File(expectedFilePath);
response = FileUtils.contentEquals(got, expected); // Here it is the key
} catch (IOException e) {
// Nothing to do Yay!
}
Assert.assertTrue(response);
它之所以有效,是因为如果我手动比较两个文件,例如通过diff 命令,它们是完全相同的。现在。
我的队友用 Windows 笔记本电脑编写代码,但当他运行测试时,它就坏了!我们开始调试。
在视觉上,两个文件是相同的;我的意思是在 human 版本中,您无法意识到任何区别。但是如果在 Cwin 终端中我们执行:
diff expected.csv got.csv windows 认为每一行都不一样
并且测试失败了。
有什么问题,是操作系统吗?如果这是真的,有没有办法比较文件内容不依赖于操作系统
【问题讨论】:
标签: java csv junit operating-system