views:

206

answers:

2

I'm writing some jUnit tests that depend on data files. Where should those data files go? And how would I (in the jUnit tests) get the location of that directory?

In Python, I would use something similar to:

datadir = os.dirname(__file__) + "/data/"
+5  A: 

Kind of depends on what you're using the data files for, but in general, just create a package and make sure it's on your classpath. To load a properties file from the "data" package, add a "MyData.props" file and you can use load a properties file like:

this.getClass().getClassLoader().getResourceAsStream("/data/MyData.props");

Again, not exactly sure if this answers your question since I'm not 100% sure what you're trying to do, but I hope it helps a little.

Todd R
+2  A: 

Keep your test data close to your test classes (same package). As todd.run suggested, use getResourceAsStream() to access your data files.

bwalliser