HI guys,
Most unit tests are working directory independent (which is a good thing),
but some unit tests are forced to use the working directory to find the
module or project directory,
so they can:
- Write a file to "MODULE_DIR/target", such as a temp file. Hint: use
File.createTempFile() instead if possible.
- Write a file to "MODULE_DIR/local", such as a benchmark log. That
local directory isn't cleaned with "mvn clean" and isn't in git either.
- Retrieve a non-classpath file. Hint: Put the file in
src/test/resources and use getClass().getResource(...) instead if possible.
By default, Maven, Gradle, Jenkins, ... sets the working directory to
the module directory.
By default, Eclipse sets it to the project directory.
For example:
droolsjbpm/
droolsjbpm/drools = project dir (unless it's droolsjbpm in some setups)
droolsjbpm/drools/drools-compiler = module dir
So I suggest we do the following:
- Avoid having to use the working dir in our tests
- Presume that the working dir is always the module dir - if we have no
other choice but to use it.
--
With kind regards,
Geoffrey De Smet
Show replies by date