我正设法把我的项目打包。但是,在执行打包之前,它会自动运行测试。测试在数据库中插入一些内容。这不是我想要的,我需要避免在打包应用程序时运行测试。有人知道如何运行没有测试的包吗?
当前回答
那些不想跳过测试用例的人。 就在主测试类注释或删除注释的上面:
//@SpringBootTest
然后,当Maven构建一个应用程序时,它仍然会在这个类中运行测试,但不会运行SpringBoot应用程序,因此不会测试到DB的连接,构建将成功。
其他回答
mvn package -Dmaven.test.skip=true
下面两个命令是最有用的
mvn clean package -Dmaven.test.skip=true
mvn clean package -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!
在Inllij IDEA中,还有一个选项可以跳过测试目标。
mvn clean install -DskipTests
推荐文章
- 为什么“System.out。”println“工作在Android?
- 在Java中什么时候使用可变参数?
- Mockito的argumentCaptor的例子
- 我如何告诉Spring Boot哪个主类用于可执行jar?
- 如何将Java8流的元素添加到现有的列表中
- 在Java 8中是否可以转换流?
- 不区分大小写的字符串作为HashMap键
- 什么是maven中的“pom”打包?
- 在Java中创建一个自定义事件
- 创建正则表达式匹配数组
- 我如何在Java中初始化一个全零的数组列表?
- 主体、使用者和主体之间的意义和区别是什么?
- 将字节转换为十六进制
- HashSet和HashMap的区别?
- 我如何有效地解析HTML与Java?