How change default root in JUnit tests? Relative path problem.

At the top of my JUnit tests, I want to be able to define relative path variables like:

String BLAH="/apple/orange/pear.xml";

But then IntelliJ insists on looking for C:\Documents and Settings\me\IdeaProjects\foo/apple/orange/pear.xml instead of for z:/foo/apple/orange/pear.xml:

In this module, I've told IntelliJ 4.5 that my source is in z:\foo.

IntelliJ did also create a directory C:\Documents and Settings\me\IdeaProjects\foo\, but I guess it needs that internally.

How can I make IntelliJ look in z:/foo instead?

Thanks much,
/r:b:

2 comments

Richard Bondi wrote:

At the top of my JUnit tests, I want to be able to define relative path variables like:

String BLAH="/apple/orange/pear.xml";

But then IntelliJ insists on looking for C:\Documents and Settings\me\IdeaProjects\foo/apple/orange/pear.xml instead of for z:/foo/apple/orange/pear.xml:

In this module, I've told IntelliJ 4.5 that my source is in z:\foo.

IntelliJ did also create a directory C:\Documents and Settings\me\IdeaProjects\foo\, but I guess it needs that internally.

How can I make IntelliJ look in z:/foo instead?

Thanks much,
/r:b:


It's not IDEA that insists on searching files in "C:\Documents and Settings\...".
This is the JVM's normal behavior to resolve relative paths. IDEA and its configuration
have no influence on that.

What you are looking for is to change the working directory of your JUnit run-configuration
because this is what the VM is using to construct an absolute path from a relative one.
Incidentally, the default working directory is set to the project file's directory (you chose
that when creating the project), which is in your case under "C:\Documents and Settings\...".
Set this to z:\foo in the run-config and you're done.

HTH,
Sascha

0

If I understand you right, that's not working. To use my actual values:

In my JUnit working directory, I put:

z:/wf/mgr/hotfix/build

In the JUnit test, I did:
File fu = new Fild("xml/tests/foo.xml");
System.out.println(fu.getAbsolutePath());

The result:

z:/xml/tests/foo.xml

which is of course completely wrong.

Any ideas?
Thanks,
/r:b?

0

Please sign in to leave a comment.