我正设法把我的项目打包。但是,在执行打包之前,它会自动运行测试。测试在数据库中插入一些内容。这不是我想要的,我需要避免在打包应用程序时运行测试。有人知道如何运行没有测试的包吗?


当前回答

最好和最简单的方法是,在IntelliJ Idea的“Maven Project”窗口中,不要点击测试按钮。我希望我帮到你了。祝你有愉快的一天。

其他回答

You are, obviously, doing it the wrong way. Testing is an important part of pre-packaging. You shouldn't ignore or skip it, but rather do it the right way. Try changing the database to which it inserts the data(like test_db). It may take a while to set it up. And to make sure this database can be used forever, you should delete all the data by the end of tests. JUnit4 has annotations which make it easy for you. Use @Before, @After @Test annotations for the right methods. You need to spend sometime on it, but it will be worth it!

下面两个命令是最有用的

mvn clean package -Dmaven.test.skip=true 
mvn clean package -DskipTests

谢谢

您可以使用任何maven目标,如包/清洁安装

解决方案:1(包目标)

mvn package -Dmaven.test.skip
mvn package -Dmaven.test.skip=true
mvn package -DskipTests

解决方案:2(清洁安装目标)

mvn clean install -Dmaven.test.skip
mvn clean install -Dmaven.test.skip=true
mvn clean install -DskipTests

解决方案:3(在pom.xml文件中)

您可以在pom文件中使用maven-跳过-测试,而无需提供 DskipTests、dmarvin .test.skip等属性

Pom.xml

<properties>
        <java.version>1.8</java.version>
        <maven.test.skip>true</maven.test.skip>
</properties>

以后可以使用maven命令:mvn clean安装/mvn包

参考:https://www.baeldung.com/maven-skipping-tests

如果你不想设置命令行参数,你可以把这个插件配置添加到你的pom:

<plugin>
  <groupId>org.apache.maven.plugins</groupId>
  <artifactId>maven-surefire-plugin</artifactId>
  <configuration>
    <skipTests>true</skipTests>
  </configuration>
</plugin>

您可以添加-DskipTests或-Dmaven.test。对于跳过测试的任何MVN命令,Skip =true。在你的情况下,它将如下所示:

mvn package -DskipTests

OR

mvn package -Dmaven.test.skip=true