通过Toggle 'Skip Tests' Mode跳过测试解决数据库插入两条数据的问题
前段时间在做一个Maven项目的小功能时,需要将数据存储进数据库,但是却遇到了插入一条记录,执行成功后,数据库却存入两条数据的情况。并且每次执行都会输出如下的信息:
[INFO] Scanning for projects...
[INFO]
[INFO] --------------------------< org.example:crud >--------------------------
[INFO] Building crud Maven Webapp 1.0-SNAPSHOT
[INFO] --------------------------------[ war ]---------------------------------
[INFO]
[INFO] --- maven-resources-plugin:3.0.2:resources (default-resources) @ crud ---
[INFO] Using 'UTF-8' encoding to copy filtered resources.
[INFO] Copying 5 resources
[INFO]
[INFO] --- maven-compiler-plugin:3.8.0:compile (default-compile) @ crud ---
[INFO] Nothing to compile - all classes are up to date
[INFO]
[INFO] --- maven-resources-plugin:3.0.2:testResources (default-testResources) @ crud ---
[INFO] Using 'UTF-8' encoding to copy filtered resources.
[INFO] Copying 0 resource
[INFO]
[INFO] --- maven-compiler-plugin:3.8.0:testCompile (default-testCompile) @ crud ---
[INFO] Changes detected - recompiling the module!
[INFO] Compiling 1 source file to G:\IdeaProjects\crud\target\test-classes
[INFO]
[INFO] --- maven-surefire-plugin:2.22.1:test (default-test) @ crud ---
[INFO] Tests are skipped.
[INFO]
[INFO] --- maven-war-plugin:3.2.2:war (default-war) @ crud ---
[INFO] Packaging webapp
[INFO] Assembling webapp [crud] in [G:\IdeaProjects\crud\target\crud]
[INFO] Processing war project
[INFO] Copying webapp resources [G:\IdeaProjects\crud\src\main\webapp]
[INFO] Webapp assembled in [307 msecs]
[INFO] Building war: G:\IdeaProjects\crud\target\crud.war
[INFO]
[INFO] --- maven-install-plugin:2.5.2:install (default-install) @ crud ---
[INFO] Installing G:\IdeaProjects\crud\target\crud.war to E:\Programming\Maven\maven-repository\org\example\crud\1.0-SNAPSHOT\crud-1.0-SNAPSHOT.war
[INFO] Installing G:\IdeaProjects\crud\pom.xml to E:\Programming\Maven\maven-repository\org\example\crud\1.0-SNAPSHOT\crud-1.0-SNAPSHOT.pom
[INFO] ------------------------------------------------------------------------
[INFO] BUILD SUCCESS
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 3.750 s
[INFO] Finished at: 2021-04-10T04:28:03+08:00
[INFO] ------------------------------------------------------------------------
经过多次测试检查后,发现通过IntelliJ IDEA找到Maven Projects面板,顶部有一个Toggle 'Skip Tests' Mode 图标(命令行方式:mvn clean package -Dmaven.test.skip=true
),选中它后再执行package
或者install
打包就会跳过测试。
最后再去执行自己的业务代码,插入成功且只有一条记录!后续对该功能问题有更好的理解再回来补充吧。
本文来自博客园,作者:Schieber,转载请注明原文链接:https://www.cnblogs.com/xiqingbo/p/issue-03.html