Q:

jUnit: Externalize expected string output

I need to test the string output of a method for various parameters. My problem is that it produces quite a large output, and it is becomes rather tedious to construct the expected output using a java String.
I thought of externalizing the expected output into a file, but I am running into issues such as carriage returns, whitespace differences, etc. 
I was wondering if there is another more practical way to compare two large Strings in jUnit.
Thank you 

A:

Reading a String from a file without corrupting it is very possible (How do I create a Java string from the contents of a file?). If your test is failing the comparison, by definition either the expected or the actual result is wrong: as the author of this test, you will need to decide which.
You may be able to avoid a literal comparison by asserting properties: test that it contains some substring, for example, or the expected number of newlines.
In general, testing a large string suggests that you're trying to test a large system's behaviour in one single test. Consider breaking the tests down into smaller units, so the components can be verified individually. This will also give you much clearer indications of where problems are.

