This Bugzilla instance is a read-only archive of historic NetBeans bug reports. To report a bug in NetBeans please follow the project's instructions for reporting issues.
[ BUILD # : 200408171800 ] [ JDK VERSION : J2SE 1.5.0 ] When running a project user.dir is set to the project directory, which seems sensible enough. However, when running tests it is set to netbeans bin directory which seems much less useful. Should user.dir not be the project directory when running tests as well as the project app?
Purely accidental that the CWD is set to the project dir in the case of running the project; seems that Ant's <java> defaults the 'dir' attr to ${basedir} (certainly not intentional on our part), and I guess <junit> does not. Could be made to for consistency. Anyway your program should probably not rely on the current working directory, and your tests definitely should not. If you need to pass some file paths to your tests, do so explicitly. I will add the ability to put in your project.properties e.g. test-sys-prop.sample.files=${basedir}/test-samples which you could then use inside a unit test via new File(System.getProperty("sample.files"))
In my particular case, the test is creating a file which then gets used and finally tidied up. I just needed some safe place to put it.
Right, common case. Pass in a scratch directory as a system property (e.g. "${basedir}/build/test/work"). Or use java.io.File's facility for making temporary files (set to delete on exit, for example, or delete in tearDown).
committed * Up-To-Date 1.13 java/j2seproject/src/org/netbeans/modules/java/j2seproject/Bundle.properties committed * Up-To-Date 1.24 java/j2seproject/src/org/netbeans/modules/java/j2seproject/J2SEProjectGenerator.java committed * Up-To-Date 1.30 java/j2seproject/src/org/netbeans/modules/java/j2seproject/resources/build-impl.xsl
FYI: see issue 43194: the working directory is configurable now in project UI in Running Project panel.
*But* I asked for that to be reverted in the case of unit tests, so that they are always run with cwd set to the project basedir, for safety. (As mentioned here, you can pass useful paths to them using test-sys-prop.* Ant properties.)