next up previous contents
Next: Test Data in a Up: Test Data Organization Previous: Test Data in a   Contents

Temporary Test Data (class ResourceFileRepo)

If test cases need to modify their test data, but test data repository needs to remain intact, it may be required to create copies of test data and let test cases modify those copies.

Repo provides class junit.extensions.repo.ResourceFileRepo that may assist in this situation.

Class ResourceFileRepo creates temporary files from resources by copying their content. Suppose that the test case MyTest has resource test.properties in the same package. ResourceFileRepo is constructed and used as follows:

import java.io.IOException;
...
protected void setUp() throws IOException {
    repo = new ResourceFileRepo();
}
...
File file = repo.getFile("test.properties");

Behind the scenes ResourceFileRepo will get the resource named as test.properties, create a new temporary file test.properties, copy the resource to the temporary file, and return a handle to that file.

Note that java.io.IOException may be thrown if I/O error occurs while working with temporary files.

All temporary files created by ResourceFileRepo will be deleted at the end.

See also: