I have some code that references a filename. On the server, this reference is relative to my war directory. When I’m running tests, though, the relative root doesn’t seem to be set – only absolute paths, starting at the root of my local HD, actually find the files.
I’m testing in the context of an AppEngine LocalServiceTestHelper, which returns my war directory in its getAppDir method, but still the code can’t understand the relative path.
How can I set the root for relative filenames in JUnit tests?
There are a number of options. In any case, I’d encapsulate the file access (or at least the file path resolution) in a separate class. That way, you could: