Reputation: 24484
According to documentation,
By default the classes in the java.io package always resolve relative pathnames against the current user directory. This directory is named by the system property user.dir, and is typically the directory in which the Java virtual machine was invoked.
So, according to it, if I run a JUnit class from the popup menu, choosing JUnit test, the current folder should be the folder in which the test class lies.
But really it takes the Default Working Directory from the page of Run Configurations - Environment page for the last Run Configuration used. So, if the test uses files with relative paths, mostly it cannot be launched correctly from the popup menu.
Even if I create a Run Configuration for the JUnit test class, yes, it will automatically set its Default Working Directory (On Run Configurations - Environment page) to the folder where the test file is. But still, used through popup menu, it again takes the Default Working Directory from the last Run Configuration used.
How can I set default directory or Eclipse somehow so, that I will can launch my test classes with the current folder according to documentation?
Upvotes: 1
Views: 2223
Reputation: 39651
You didn't provide an example of what you try to do but I guess you try to load some file which you need in your test. If thats the case you should better change the way you load the file.
YourTestClass.class.getResource("filename")
orYourTestClass.class.getResourceAsStream("filename")
is what you should use. It looks up a file relative to YourTestClass
.
Upvotes: 1