Our Java code (not the test code) reads files from the current directory, which means the working directory needs to be set properly whenever we run the code.
When launching a JUnit test from within Eclipse, a launch configuration automatically gets created. The problem is, that the working directory in that launch configuration is always by default the root project directory which is always wrong, the test fails, I have to open the launch configuration dialog, change the working directory and relaunch the test. This is very annoying. The same thing happens when I run a single test method.
I've already considered these:
All in all, it looks like it's responsibility of Eclipse, not the code.
Is there a way to set the default working directory for all future, newly created JUnit launch configurations?
In the Working directory section, click on the "Other" radio button. Click the "Workspace..." button and navigate to the desired working directory, typically the "bin" directory. Click "OK". Click "Apply" to save the changes and then proceed below to the next step to create the .
To use JUnit you must create a separate . java file in your project that will test one of your existing classes. In the Package Explorer area on the left side of the Eclipse window, right-click the class you want to test and click New → JUnit Test Case. A dialog box will pop up to help you create your test case.
In Eclipse, a launch configuration contains all the information to run or debug a program. A DS-5 debug launch configuration typically describes the target to connect to, the communication protocol or probe to use, the application to load on the target, and debug information to load in the debugger.
This is a subjective answer:
I believe you're doing your tests wrong, you shouldn't be loading the files from the JUnit using relative or complete paths, but instead, have them as resources in the project (add them to the build path) and load them as resources in the JUnit tests. This way if something changes on the filesystem, someone uses a different filesystem or IDE but still has them in the build path (as source folders) you're not going to have a problem.
I'm unsure if this is what you mean but if you really want to change it go to the Run Configuration options -> Your JUnit -> Arguments tab, at the bottom (Eclipse 3.4) you see Working Directory, click 'other' and change it from there.
As far as I can tell, there's no way of changing the default working directory for future JUnit launch configurations in Eclipse 3.4. This issue has also been reported as a bug in the Eclipse bug database.
However, it is possible in IDEA. There's the Edit Defaults button for setting all kinds of defaults for each launch config type separately.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With