Reputation: 2269
We have a java web application that generates files (zip) and drops it to file system. Is there a way to bring this within the realm of test automation - i.e. validate that a) file/packet got generated b) the packet contents match and c) individual files have necessary data. the contents of the packet are typically pdf, txt and xml files
Are there any tools/ methods to effectively test this
Upvotes: 0
Views: 770
Reputation: 6940
I have similar tasks like yours, but in XLSX format. Maybe my approach can help you:
In my case I have report_generator which prints such results as execution_flow, regression etc.
So as bottom line - yes this definitely must be put into the realm of test automation
Upvotes: 1
Reputation: 53809
You can use TemporaryFolder from Junit:
The TemporaryFolder Rule allows creation of files and folders that are guaranteed to be deleted when the test method finishes (whether it passes or fails)
public class HasTempFolder {
@Rule
public TemporaryFolder folder = new TemporaryFolder();
@Test
public void testUsingTempFolder() throws IOException {
File createdFile= folder.newFile("myfile.txt");
File createdFolder= folder.newFolder("subfolder");
// ...
}
}
For checking file contents, FileUtils from Apache Commons IO has a lot of very useful methods.
Upvotes: 1
Reputation: 272457
The TDD way would be to inject mock objects that handle the actual file writing.
In practice, you could just use JUnit to automatically create temporary directories for the lifespan of a test-case (with a TemporaryFolder
rule; see http://junit.org/javadoc/4.9/org/junit/rules/TemporaryFolder.html).
Upvotes: 1