比较文本文件w / Junit [英] Comparing text files w/ Junit

查看:122
本文介绍了比较文本文件w / Junit的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我比较junit中的文本文件:

I am comparing text files in junit using:


  public static void assertReaders(BufferedReader expected,
          BufferedReader actual) throws IOException {
    String line;
    while ((line = expected.readLine()) != null) {
      assertEquals(line, actual.readLine());
    }

    assertNull("Actual had more lines then the expected.", actual.readLine());
    assertNull("Expected had more lines then the actual.", expected.readLine());
  }

这是比较文本文件的好方法吗?什么是首选?

Is this a good way to compare text files? What is preferred?

推荐答案

junit-addons 对此有很好的支持: FileAssert

junit-addons has nice support for it: FileAssert

它会给你例外:

junitx.framework.ComparisonFailure: aa Line [3] expected: [b] but was:[a]

这篇关于比较文本文件w / Junit的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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