我正设法把我的项目打包。但是,在执行打包之前,它会自动运行测试。测试在数据库中插入一些内容。这不是我想要的,我需要避免在打包应用程序时运行测试。有人知道如何运行没有测试的包吗?
当前回答
mvn clean install -DskipTests
其他回答
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!
如果你不想设置命令行参数,你可以把这个插件配置添加到你的pom:
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<configuration>
<skipTests>true</skipTests>
</configuration>
</plugin>
你可以传递maven.test.skip标志作为JVM参数,当包阶段(以及默认生命周期中的前一个阶段)运行时跳过运行测试:
mvn package -Dmaven.test.skip=true
您还可以单独将skipTests标志传递给mvn可执行文件。如果您希望在POM中包含此信息,可以创建一个新的配置文件,在其中配置maven-surefire-plugin以跳过测试。
进行maven构建和跳过测试的一个简写是:
mvn 全新安装 -DskipTests
在Intellij中,进入“View -> Tool Windows ->”,选择“Maven Projects”。 在Lifecyle下拉菜单中,右键单击package ->,选择Create 'your-project [package]'…
输入这个值:package -Dmaven.test。skip=true -f命令行字段中的pom.xml。单击Apply,将出现Run Configurations下拉菜单以及您创建的自定义maven命令。
推荐文章
- Java中的@UniqueConstraint注释
- 如何在清洁模式下运行eclipse ?如果我们这样做会发生什么?
- 获取java.lang.ClassNotFoundException: org.apache.commons.logging.LogFactory异常
- Java中的正则表达式命名组
- c#和Java的主要区别是什么?
- 什么是NullPointerException,我如何修复它?
- 在Java中使用“final”修饰符
- 无法在Flutter上找到捆绑的Java版本
- 如何在Kotlin解析JSON ?
- 如何在新的材质主题中改变背面箭头的颜色?
- 如何设置OkHttp连接超时
- 用于桌面应用程序的Swing vs JavaFx
- 为什么这个Java程序会终止,尽管它显然不应该(也没有)终止?
- Maven project.build.directory
- 使用split("|")按管道符号拆分Java字符串