Loads files containing test input and output into memory. If there are differences, writes out a log file containing the actual output.
Typical usage is as follows. A testcase class defines a method
package com.acme.test; public class MyTest extends TestCase { public DiffRepository getDiffRepos() { return DiffRepository.lookup(MyTest.class); } @Test public void testToUpper() { getDiffRepos().assertEquals("${result}", "${string}"); } @Test public void testToLower() { getDiffRepos().assertEquals("Multi-line\nstring", "${string}"); } }
There is an accompanying reference file named after the class, com/acme/test/MyTest.ref.xml
:
<Root> <TestCase name="testToUpper"> <Resource name="string"> <![CDATA[String to be converted to upper case]]> </Resource> <Resource name="result"> <![CDATA[STRING TO BE CONVERTED TO UPPER CASE]]> </Resource> </TestCase> <TestCase name="testToLower"> <Resource name="result"> <![CDATA[multi-line string]]> </Resource> </TestCase> </Root>
If any of the testcases fails, a log file is generated, called com/acme/test/MyTest.log.xml
containing the actual output. The log file is otherwise identical to the reference log, so once the log file has been verified, it can simply be copied over to become the new reference log.
If a resource or testcase does not exist, DiffRepository
creates them in the log file. Because DiffRepository is so forgiving, it is very easy to create new tests and testcases.
The {@link #lookup} method ensures that all test cases share the sameinstance of the repository. This is important more than one one test case fails. The shared instance ensures that the generated .log.xml
file contains the actual for both test cases.
|
|