Wednesday, June 22, 2011

FileNotFoundException when running a unit test in IntelliJ

If you are running a unit test in IntelliJ that needs to load a test file, you might come across this error.
java.io.FileNotFoundException: src\test\resources\testFile.xml (The system cannot find the path specified)
The problem may be that by default, IntelliJ sets the working directory to be the project root. If you are working on a maven project or something else with a complicated project structure, then you probably want it to look instead at the module root.

This is easy enough to configure. Simply go to:

Edit Configurations -> Defaults -> JUnit -> Working Directory

Set this value to $MODULE_DIR$ and you are done!

Also remember to delete any existing JUnit configurations so that it will pick up the default you have just set.

3 comments:

Patrick Healy said...

YOU ARE THE BEST!

Anonymous said...

What to do when having the same problem in Eclipse?

Himalay said...

just what I was looking since yesterday.. thanks for sharing!