Classpaths with JUnit tests

What is the best way to set a classpath for config files within a JUnit test?

The problem I am having is with JUnit tests that require config files or other setup from the project, and require the resource to be loaded from the classpath. If I have a config directory with the files in it, then as far as I see I need to add the directory to the classpath of the module to allow the test case to class load the resource.

This leads to two problems:

1) Unmanageable classpaths that do not reflect the build requirements of the system

2) IntelliJ moves the directory to underneath the Libraries node on the Project tree, which in a large project with many 3rd party libraries is completely the wrong place to have them.

This is not a contrived example, we have many tests that require Hibernate mapping files, Spring contexts or in the case of JsTester javascript files to be on the classpath for the test to run.

Either I am missing something in IntelliJ (we use 5.1 and are evaluating 6.0) or this seems to be a rather large problem with the IDE. At this stage it is preventing me from recommending that we continue using IntelliJ or upgrading to version 6.0.

Thanks in advance,
Mat Robinson.

Please sign in to leave a comment.