<!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. I thought the Groovy presentation<br>
implied that JUnit didn't have such an animal. <br>
<br>
I would suggest writing a simple method like this:<br>
<br>
String[] load(File file) {<br>
// Load the file and each element equals one line<br>
}<br>
<br>
Then you could just use it in your test cases:<br>
<br>
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 = 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>
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. The old environment
is no longer available. 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). The first time you create
a testcase, you visually inspect the text and see if it is ok:<br>
This is the first line of text output<br>
I expect this result on the second line<br>
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>
> 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>
assertEquals(lines[0], "This is the first line of text output");<br>
assertEquals(lines[1], "I expect this result on the second line");<br>
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>