I wanted to add a test to my small project (please note I removed some bits from the code & changed package names, so if there\'s any error you see regarding this it might b
You shouldn't override your
setting in the POM's
element unless you have a good reason to. This attribute determines where Maven looks for non-test code. The default value for this attribute is src/main/java
. The
attribute sets the path to test code (this defaults to src/test/java
. By setting the
to simply src
, Maven considers that entire directory to contain main application code. Since the src
directory contains src/test/java
, Maven then tries to compile your test code as part of the main application.
This is significant because when compiling the main application (during the compile
phase), Maven omits dependencies with test
scope. Test code is compiled in a separate phase (the test-compile
phase) after the main compile.
So since Maven tried to compile your test code as part of the main application, it omitted the junit
dependency, and they weren't available on the classpath. The solution here is to simply not specify the
element in the POM.