Maven打包跳過單元測試

Maven在打包時可以使用兩種方式來跳過單元測試:

  • -DskipTests
  • -Dmaven.test.skip=true

兩者的區別如下:

skipTests:不執行測試用例,但編譯測試用例類生成相應的class文件至target/test-classes下,執行結果如下:

[INFO] --- maven-resources-plugin:2.6:testResources (default-testResources) @ elastic-demo ---
[INFO] Using 'UTF-8' encoding to copy filtered resources.
[INFO] Copying 1 resource
[INFO]
[INFO] --- maven-compiler-plugin:3.1:testCompile (default-testCompile) @ elastic-demo ---
[INFO] Changes detected - recompiling the module!
[INFO] Compiling 1 source file to D:\IdeaProjects\elastic-demo\target\test-classes
[INFO]
[INFO] --- maven-surefire-plugin:2.18.1:test (default-test) @ elastic-demo ---
[INFO] Tests are skipped.
[INFO]

maven.test.skip=true:不執行測試用例,也不編譯測試用例類,執行結果如下:

[INFO] --- maven-resources-plugin:2.6:testResources (default-testResources) @ elastic-demo ---
[INFO] Not copying test resources
[INFO]
[INFO] --- maven-compiler-plugin:3.1:testCompile (default-testCompile) @ elastic-demo ---
[INFO] Not compiling test sources
[INFO]
[INFO] --- maven-surefire-plugin:2.18.1:test (default-test) @ elastic-demo ---
[INFO] Tests are skipped.
[INFO]
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章