I have a maven project with a module
/myProject pom.xml /myModule pom.xml /foo bar.txt
Consider a Junit in myModule>
Solution inspired by Guillaume :
In Run->Edit configuration->Defaults->JUnit->Working directory set the value $MODULE_DIR$ and Intellij will set the relative path in all junits just like Maven.
Run->Edit configuration->Defaults->JUnit->Working directory
$MODULE_DIR$