<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
  <meta content="text/html;charset=ISO-8859-1" http-equiv="Content-Type">
  <title></title>
</head>
<body bgcolor="#ffffff" text="#000000">
Actually, JUnit has assertArrayEquals method so reading the files <br>
into arrays and testing them would be better since it would also<br>
take line order into account.&nbsp; I thought the Groovy presentation<br>
implied that JUnit didn't have such an animal.&nbsp; <br>
<br>
I would suggest writing a simple method like this:<br>
<br>
&nbsp;&nbsp;&nbsp; String[] load(File file) {<br>
&nbsp;&nbsp;&nbsp; &nbsp;&nbsp; // Load the file and each element equals one line<br>
&nbsp;&nbsp;&nbsp; }<br>
<br>
Then you could just use it in your test cases:<br>
<br>
&nbsp;&nbsp;&nbsp; assertArrayEquals(load(new File("Golden.txt")), load(new
File("Ouput.txt")));<br>
<br>
<br>
<blockquote cite="mid:4900CE18.1020702@sun.com" type="cite">
  <meta content="text/html;charset=ISO-8859-1" http-equiv="Content-Type">
  <title></title>
How about leveraging some Groovy as put forward in the last
presentation.<br>
  <br>
List golden&nbsp; = new File("Golden.txt").readLines();<br>
List current = new File("CurrentTest.txt").readLines();<br>
  <br>
assertTrue(current.containsAll(golden));<br>
assertTrue(golden.containsAll(current));<br>
  <br>
You could also just write an equivalent<br>
  <br>
&nbsp;&nbsp;&nbsp;&nbsp; List readLines(File file);<br>
  <br>
method in Java yourself.<br>
  <br>
  <br>
  <br>
  <br>
Send Here wrote:
  <blockquote cite="mid:444269.99564.qm@web51112.mail.re2.yahoo.com"
 type="cite">
    <style type="text/css"><!-- DIV {margin:0px;} --></style>
    <div
 style="font-family: arial,helvetica,sans-serif; font-size: 10pt;">I
recently started using JUnit and previously used a custom in-house
testing environment which was heavily text-based.&nbsp; The old environment
is no longer available.&nbsp; I'm wondering if there's an easy way to adapt
JUnit to text-based/diff-based testing, or if I should use another
testing framework entirely, or if I am just abusing JUnit and should
find a way to use it how it expects to be used.<br>
    <br>
By "text-based" I mean every testcase produces some kind of text output
which can be saved into a file and diff'ed against a previously
approved text output (aka golden reference).&nbsp; The first time you create
a testcase, you visually inspect the text and see if it is ok:<br>
&nbsp;&nbsp; This is the first line of text output<br>
&nbsp;&nbsp; I expect this result on the second line<br>
&nbsp;&nbsp; And this on the third line<br>
If that's good, you copy the output to a golden reference area, and
then the next time you run it if the current results have a diff then
you know you have something to fix:<br>
&nbsp;&nbsp; &gt; I didn't expect this on the second line<br>
    <br>
I suppose I could read the text as an array of Strings and write a
bunch of JUnit assert stmts for this instead, e.g.<br>
&nbsp;&nbsp; assertEquals(lines[0], "This is the first line of text output");<br>
&nbsp;&nbsp; assertEquals(lines[1], "I expect this result on the second line");<br>
&nbsp;&nbsp; assertEquals(lines[2], "And this on the third line");<br>
...but that will become very cumbersome very quickly when there is a
lot of output, and also cumbersome when you change things intentionally
and need to update the golden reference.<br>
    <br>
    </div>
    <br>
    <pre wrap=""><hr size="4" width="90%">
_______________________________________________
Web Site - <a moz-do-not-send="true" class="moz-txt-link-freetext"
 href="http://www.pjug.org/">http://www.pjug.org/</a>
Javamail mailing list
<a moz-do-not-send="true" class="moz-txt-link-abbreviated"
 href="mailto:Javamail@pjug.org">Javamail@pjug.org</a>
<a moz-do-not-send="true" class="moz-txt-link-freetext"
 href="http://www.pjug.org/mailman/listinfo/javamail">http://www.pjug.org/mailman/listinfo/javamail</a>
  </pre>
  </blockquote>
  <br>
  <pre wrap="">_______________________________________________
Web Site - <a class="moz-txt-link-freetext" href="http://www.pjug.org/">http://www.pjug.org/</a>
Javamail mailing list
<a class="moz-txt-link-abbreviated" href="mailto:Javamail@pjug.org">Javamail@pjug.org</a>
<a class="moz-txt-link-freetext" href="http://www.pjug.org/mailman/listinfo/javamail">http://www.pjug.org/mailman/listinfo/javamail</a>
  </pre>
</blockquote>
<br>
</body>
</html>