views:

21

answers:

1

I've written an xml parser, and I've written a unit test to go with it. Where should I store the actual xml file to be used by the test?

Should I just store it under test/unit/whatever package the test is in?

+1  A: 

It depends on several things:

  • is this going to be a single test, or are you planning to develop more tests (and test files)? In the former case, it does not matter so much, while in the latter case you might want to think about orgnaizing your test data files in advance. In any case I would store the test file(s) in a separate test directory structure (which may nevertheless mimic the package structure).
  • is this a kind of "smoketest" to be published with the parser (this is what your description suggests to me), or only for internal use? In the former case you might prefer organizing your test files in a user-friendly manner; users typically are not concerned so much with the internal package structure of your app, but with ease of use and logical organization. This would dictate organizing (and naming!) the test files according to the use cases they are related.

Update: So, multiple unit test files for internal use. I would then just put them into a test directory, making it easy and uniform for the tests to find them. If they are in the same package where the test class is, whenever you happen to move a class to a different package, you must remember to move the xml file too, and update the file path inside the test. Otherwise the test will happily continue running with the test file in the old directory, without you noticing anything! This opens up possibilities for subtle bugs over time - like deleting a test file which seems to be unused, or worse: overwriting it with another test file...

Péter Török
I'll be developing multiple tests using multiple xml files. I don't see how users play into this. I don't think unit tests are packaged with the application.
ScArcher2
@ScArcher2 thanks, I updated my answer based on your feedback.
Péter Török