[PJUG Javamail] can I do text/diff-based testing with JUnit?

Send Here component0 at yahoo.com
Thu Oct 23 13:26:08 EDT 2008


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.

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:
   This is the first line of text output
   I expect this result on the second line
   And this on the third line
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:
   > I didn't expect this on the second line

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.
   assertEquals(lines[0], "This is the first line of text output");
   assertEquals(lines[1], "I expect this result on the second line");
   assertEquals(lines[2], "And this on the third line");
...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.


      
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://www.pjug.org/pipermail/javamail/attachments/20081023/e43869ab/attachment.html 


More information about the Javamail mailing list