我正设法把我的项目打包。但是,在执行打包之前,它会自动运行测试。测试在数据库中插入一些内容。这不是我想要的,我需要避免在打包应用程序时运行测试。有人知道如何运行没有测试的包吗?
当前回答
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!
其他回答
你可以传递maven.test.skip标志作为JVM参数,当包阶段(以及默认生命周期中的前一个阶段)运行时跳过运行测试:
mvn package -Dmaven.test.skip=true
您还可以单独将skipTests标志传递给mvn可执行文件。如果您希望在POM中包含此信息,可以创建一个新的配置文件,在其中配置maven-surefire-plugin以跳过测试。
只需提供下面提到的命令,它将忽略执行测试用例(但将编译测试代码):
mvn 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
在Intellij中,进入“View -> Tool Windows ->”,选择“Maven Projects”。 在Lifecyle下拉菜单中,右键单击package ->,选择Create 'your-project [package]'…
输入这个值:package -Dmaven.test。skip=true -f命令行字段中的pom.xml。单击Apply,将出现Run Configurations下拉菜单以及您创建的自定义maven命令。
注意- dmarvin .test。跳过阻止Maven构建test-jar工件。
如果您想跳过测试,但按照正常的构建使用创建工件:
-Dmaven.test.skip.exec
推荐文章
- 在流中使用Java 8 foreach循环移动到下一项
- 访问限制:'Application'类型不是API(必需库rt.jar的限制)
- 用Java计算两个日期之间的天数
- 如何配置slf4j-simple
- 在Jar文件中运行类
- 带参数的可运行?
- 我如何得到一个字符串的前n个字符而不检查大小或出界?
- 我可以在Java中设置enum起始值吗?
- Java中的回调函数
- c#和Java中的泛型有什么不同?和模板在c++ ?
- 在Java中,流相对于循环的优势是什么?
- Jersey在未找到InjectionManagerFactory时停止工作
- 在Java流是peek真的只是调试?
- Recyclerview不调用onCreateViewHolder
- 将JSON字符串转换为HashMap