Maven won't actually let you do this. Everything in the src/test
directory structure is not on the class path when maven tries to execute the compile goal.
For instance, let's say I accidentally add the following code to my HelloWorld program:
public void badDependency() {
new HelloWorld_UT();
}
Where HelloWorld_UT
is just a standard junit test.
Even though eclipse will report no compile errors in my project, when I try to do a maven compile, I get this error:
[INFO] ------------------------------------------------------------------------
[INFO] BUILD FAILURE
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 1.297s
[INFO] Finished at: Sat May 10 23:08:29 CDT 2014
[INFO] Final Memory: 7M/17M
[INFO] ------------------------------------------------------------------------
[ERROR] Failed to execute goal org.apache.maven.plugins:maven-compiler-plugin:3.1:compile (default-compile) on project scratch: Compilation failure
[ERROR] /C:/eclipse/workspace/Scratch/src/main/java/org/drc/HelloWorld.java:[11,21] C:\eclipse\workspace\Scratch\src\main\java\org\drc\HelloWorld.java:11: cannot find symbol
[ERROR] symbol : class HelloWorld_UT
[ERROR] location: class org.drc.HelloWorld