I am working on a project with a few file formats. Some formats are specified by .xsds, others by documentation on their respective websites, and some are custom in-house formats that have no documentation. Mwahahahaha.
What's the problem?
I would like to test my file readers, but I'm not entirely sure how to go about doing this. The flow of the application is as such:
file.___ ===> read by FileReader.java ===> which creates a Model object
where the FileReader
interface is
public interface FileReader {
public Model read(String filename);
}
The Model
has a number of attributes that are populated when the file is read. It looks something like
public class Model {
List<String> as;
List<String> bs;
boolean isAPain = true;
// ...
}
What have I tried?
My only idea was to create file "generators" for each file format. These generators are basically builders which take in a few variables (eg. number of comments to generate in a file), and output a sample file which I then read in and compare the resulting Model
with the variables I used to initially generate the file.
This has a few problems, though:
- The files that it generates don't look like real files. The generator is in no way aware of context.
- It's hard to recognize if the generator has generated for edge cases since I'm the one manually setting the variables. This method is barely better than me creating a dozen sample files.
Are there any better ways to do this?
EDIT: Changed unit to integration since that's what I actually mean.
EDIT2: Here is an example of the edge cases I mentioned.
Each file represents a graph made up of vertices and edges. These vertices and edges can be attached in different ways, so:
v1 -- e1 --> v2 <-- e2 -- v3
is different from
v1 -- e1 --> v2 -- e2 --> v3
in that the direction of the edges matter. I'm not sure if this is in the scope of the question, but it's hard to think up all of the pertinent edge cases when I manually set the number of vertices, number of edges, and just generate the connections randomly.
FileReader
implementation)? Example: given the edge cases found in image file formats, for each table entry, if the row/column combination of properties are supported, there should be at least one test case (a data file) covering that combination.