Help Organizing Unit Test Data



  • <font face="Arial">Ok, this post is very noob-ish even though I swear I have some clue.  Basically I have some hard-coded paths to test data in my unit test classes that I need to remove.  The project directories are organized like this:

    projectname\test\packagenamepath\test classes for all unit tests
    </font><font face="Arial">projectname\test\test-docs for all data needed by the unit tests

    Right now the hardcoded paths are "c:....", I thought of relative paths i.e. "../../etc" but if I move a class around in the heirarchy that screws up.  It seems silly to read the root dir from a properties file, plus then I need to specify where that is when I use codeguides junit integration or an ant task.  I figure there has to be some simple way to solve this problem that I am overlooking that will work even if I move the project to a different drive/directory and that I won't have to maintain.  Any suggestions?
    </font><font face="Arial">
    </font>



  • Well, I dug up the answer to my own question, since "test-docs" is in the class path in each of my tests, I can read in a data file using code like this:

    this.getClass().getResourceAsStream("/test-docs/filename");

    So now all paths are relative to the root as long as the classpath is set up correctly.


Log in to reply
 

Looks like your connection to What the Daily WTF? was lost, please wait while we try to reconnect.