使用maven執行編譯和測試
1.maven執行編譯
(1).在pom.xml上點右鍵,選擇Maven build...
(2).在Goals里輸入clean complie,執行編譯
執行結果:
[INFO] Scanning for projects...
[INFO]
[INFO] ------------------------------------------------------------------------
[INFO] Building helloworld 0.0.1-SNAPSHOT
[INFO] ------------------------------------------------------------------------
[INFO]
[INFO] --- maven-clean-plugin:2.4.1:clean (default-clean) @ helloworld ---
[INFO] Deleting D:\ProgramData\03work\helloworld\target
[INFO]
[INFO] --- maven-resources-plugin:2.5:resources (default-resources) @ helloworld ---
[debug] execute contextualize
[INFO] Using 'UTF-8' encoding to copy filtered resources.
[INFO] skip non existing resourceDirectory D:\ProgramData\03work\helloworld\src\main\resources
[INFO]
[INFO] --- maven-compiler-plugin:2.3.2:compile (default-compile) @ helloworld ---
[INFO] Compiling 1 source file to D:\ProgramData\03work\helloworld\target\classes
[INFO] ------------------------------------------------------------------------
[INFO] BUILD SUCCESS
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 1.047s
[INFO] Finished at: Tue Jul 16 17:50:51 CST 2013
[INFO] Final Memory: 5M/15M
[INFO] ------------------------------------------------------------------------
2.Maven執行測試
(1).在pom.xml執行maven test,如圖
執行結果
[INFO] Scanning for projects...
[INFO]
[INFO] ------------------------------------------------------------------------
[INFO] Building helloworld 0.0.1-SNAPSHOT
[INFO] ------------------------------------------------------------------------
[INFO]
[INFO] --- maven-resources-plugin:2.5:resources (default-resources) @ helloworld ---
[debug] execute contextualize
[INFO] Using 'UTF-8' encoding to copy filtered resources.
[INFO] skip non existing resourceDirectory D:\ProgramData\03work\helloworld\src\main\resources
[INFO]
[INFO] --- maven-compiler-plugin:2.3.2:compile (default-compile) @ helloworld ---
[INFO] Nothing to compile - all classes are up to date
[INFO]
[INFO] --- maven-resources-plugin:2.5:testResources (default-testResources) @ helloworld ---
[debug] execute contextualize
[INFO] Using 'UTF-8' encoding to copy filtered resources.
[INFO] skip non existing resourceDirectory D:\ProgramData\03work\helloworld\src\test\resources
[INFO]
[INFO] --- maven-compiler-plugin:2.3.2:testCompile (default-testCompile) @ helloworld ---
[INFO] Compiling 1 source file to D:\ProgramData\03work\helloworld\target\test-classes
[INFO]
[INFO] --- maven-surefire-plugin:2.10:test (default-test) @ helloworld ---
[INFO] Surefire report directory: D:\ProgramData\03work\helloworld\target\surefire-reports
-------------------------------------------------------
T E S T S
-------------------------------------------------------
Running com.juvenxu.helloworld.AppTest
Tests run: 1, Failures: 1, Errors: 0, Skipped: 0, Time elapsed: 0.046 sec <<< FAILURE!
Results :
Failed tests: sayHello(com.juvenxu.helloworld.AppTest): expected:<hello[1]> but was:<hello[]>
Tests run: 1, Failures: 1, Errors: 0, Skipped: 0
[INFO] ------------------------------------------------------------------------
[INFO] BUILD FAILURE
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 1.750s
[INFO] Finished at: Tue Jul 16 17:53:20 CST 2013
[INFO] Final Memory: 6M/15M
[INFO] ------------------------------------------------------------------------
[ERROR] Failed to execute goal org.apache.maven.plugins:maven-surefire-plugin:2.10:test (default-test) on project helloworld: There are test failures.
[ERROR]
[ERROR] Please refer to D:\ProgramData\03work\helloworld\target\surefire-reports for the individual test results.
[ERROR] -> [Help 1]
[ERROR]
[ERROR] To see the full stack trace of the errors, re-run Maven with the -e switch.
[ERROR] Re-run Maven using the -X switch to enable full debug logging.
[ERROR]
[ERROR] For more information about the errors and possible solutions, please read the following articles:
[ERROR] [Help 1] http://cwiki.apache.org/confluence/display/MAVEN/MojoFailureException
執行失敗,因為類方法返回的是"hello",而我在測試類里寫的是"hello1",所以失敗了,修改一下測試代碼就OK了