1, the problem arises:
The MAVEN project execution unit test executes normally, but executes the MAVEN command test, reporting an exception:
Org.apache.maven.plugins:maven-compiler-plugin:2.5.1:testcompile (Default-testcompile) on project support: Compilation failure:compilation failure:
[ERROR] E:\workspace\support\src\test\java\com\test\spring\support\ TESTSPRINGCONTEXTHOLDER.JAVA:[7,16] Error: Package org.junit does not exist
[ERROR] E:\workspace\support\src\test\java\com\test\ spring\support\testspringcontextholder.java:[16,2] Error: Cannot find Symbol
[ERROR] Symbol: class Test
[ERROR] Position: class Testspringcontextholder
[ERROR] E:\workspace\support\src\test\java\com\test\spring\support\ testspringcontextholder.java:[29,2] Error: Cannot find Symbol
[ERROR] Symbol: class before
[ERROR] Position: Class Testspringcontextholder
[ERROR] e:\workspace\support\src\test\java\com\test\spring\support\testspringcontextholder.java:[43,5] Error: Symbol not found
2. Causes of the above errors:
1), MAVEN project, unit test and run using different classpath, test using Test-classpath, run using Classpath;
2), creating a MAVEN project using the JUnit default version is 3.8.1, which uses a programmatic approach, even if the Maven dependencies directory is introduced to JUnit, but is not available, only the build path can be used to add junit support
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>3.8.1</version>
<scope>test</scope>
</dependency>
3. Solution:
To increase the version of JUnit to 4.x, the configuration code is as follows:
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<!--The default version is 3.8.1, modified to 4.x, because 3.x is used in a programmatic way, 4.x is the form of annotations. -
<version>4.11</version>
<scope>test</scope>
</dependency>
4, add: I posted above the exception directory located in ... \src\test\java\ ... No... \src\main\java\ ... , if the exception occurs in the main directory instead of the test directory, and the JUnit version is 4.x, the solution removes the scope attribute:
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<!--The default version is 3.8.1, modified to 4.x, because 3.x is used in a programmatic way, 4.x is the form of annotations. -
<version>4.11</version>
<!--Remove the scope scope, using the default compile, compile, test, run all valid scopes--
<!--<scope>test</scope>-->
</dependency>
Solution Reference: http://www.cnblogs.com/LiuChunfu/p/5598367.html