Java 从命令行中的可执行jar运行测试SpringBootTest

Java 从命令行中的可执行jar运行测试SpringBootTest,java,spring-boot,junit,spring-test-mvc,Java,Spring Boot,Junit,Spring Test Mvc,我需要运行一个包含所有测试的jar。 我可以在jar中构建所有测试类,但我不知道如何引导主类在springboot中运行junit测试。 我是否可以运行一个命令行来运行jar并启动所有测试并忽略mainclass 测试班 @ExtendWith(SpringExtension.class) @AutoConfigureMockMvc @春靴测试 @TestPropertySource(locations=“classpath:${test.config.env:application local

我需要运行一个包含所有测试的jar。 我可以在jar中构建所有测试类,但我不知道如何引导主类在springboot中运行junit测试。 我是否可以运行一个命令行来运行jar并启动所有测试并忽略mainclass

测试班

@ExtendWith(SpringExtension.class)
@AutoConfigureMockMvc
@春靴测试
@TestPropertySource(locations=“classpath:${test.config.env:application local.properties}”)
@TestMethodOrder(OrderAnnotation.class)
公共类RunIntegrationTest{
//所有测试
}
Pom.xml


4.0.0
org.springframework.boot
spring启动程序父级
2.3.2.2发布
...
...
...
...
1.8
1.8
1.8
org.springframework.boot
SpringBootStarterWeb
org.springframework.boot
弹簧起动试验
org.junit.vintage
朱尼特老式发动机
目标/类别
org.springframework.boot
springbootmaven插件
为了在命令行上从构建的jar运行所有测试,我需要执行什么


java-jar build-with-class-test-and-junit-in-it.jar#还有更多参数吗?

我有一个解决方案,可以使用
junit4
SpringRunner
在jar中运行springboot测试

创建测试类

import org.junit.FixMethodOrder;
导入org.junit.Test;//对于这种情况,不要使用org.junit.jupiter.api.test
导入org.junit.runner.RunWith;
导入org.junit.runners.MethodSorters;
导入org.springframework.beans.factory.annotation.Autowired;
导入org.springframework.boot.test.autoconfigure.web.servlet.AutoConfigureMockMvc;
导入org.springframework.boot.test.context.SpringBootTest;
导入org.springframework.test.context.TestPropertySource;
导入org.springframework.test.context.junit4.SpringRunner;
导入org.springframework.test.web.servlet.MockMvc;
@RunWith(SpringRunner.class)//使用SpringRunner代替@ExtendWith(SpringExtension.class)
@AutoConfigureMockMvc
@春靴测试
@TestPropertySource(locations=“classpath:application-${spring.profiles.active:local}.properties”)
@FixMethodOrder(MethodSorters.NAME\u升序)
公共类RunIntegrationTest{
@自动连线
私有MockMvc-MockMvc;
@试验
//…所有集成测试
@试验
//…所有集成测试
}
创建文件pom-test-jar.xml


4.0.0
org.springframework.boot
spring启动程序父级
2.3.2.2发布
...
...
...
...
1.8
1.8
1.8
org.springframework.boot
SpringBootStarterWeb
org.springframework.boot
spring引导启动器数据jpa
org.springframework.boot
弹簧起动试验
目标/类别
org.springframework.boot
springbootmaven插件
org.junit.runner.JUnitCore
真的
就这些:)

让我们创建包含测试的jar,并运行所有测试

#构建测试JAR:
mvn-f“pom test jar.xml”干净包-DskipTests
#运行测试集成
导出弹簧配置文件\u活动=hom
java-jar target/myjar.jar br.com.package.test.RunIntegrationTest
取消设置弹簧\u配置文件\u活动