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


当前回答

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!

其他回答

测试应该总是在包之前运行[1]。如果您需要关闭测试,那么您做错了什么。换句话说,你在试图解决错误的问题。找出你真正的问题所在,然后提出这个问题。听起来像是数据库相关的。

当您需要快速生成用于本地开发使用的工件时,您可能会跳过测试,但一般来说,创建工件应该始终遵循成功的测试运行。

你可以传递maven.test.skip标志作为JVM参数,当包阶段(以及默认生命周期中的前一个阶段)运行时跳过运行测试:

mvn package -Dmaven.test.skip=true

您还可以单独将skipTests标志传递给mvn可执行文件。如果您希望在POM中包含此信息,可以创建一个新的配置文件,在其中配置maven-surefire-plugin以跳过测试。

运行maven

mvn package -Dmaven.test.skip

在Inllij IDEA中,还有一个选项可以跳过测试目标。

mvn clean install -Dmaven.test.skip=true

工作为我,因为-Dskip不再工作了。