【发布时间】:2021-08-17 03:37:36
【问题描述】:
我需要运行一个包含所有测试的 jar。 我可以在 jar 中构建所有测试类,但我不知道如何启动主类以在 springboot 中运行 junit 测试。 是否可以运行命令行来运行 jar 并启动所有测试并忽略 mainclass。
测试类
@ExtendWith(SpringExtension.class)
@AutoConfigureMockMvc
@SpringBootTest
@TestPropertySource(locations = "classpath:${test.config.env:application-local.properties}")
@TestMethodOrder(OrderAnnotation.class)
public class RunIntegrationTest {
// All tests
}
Pom.xml
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>2.3.2.RELEASE</version>
<relativePath />
</parent>
<groupId>...</groupId>
<artifactId>...</artifactId>
<version>...</version>
<name>...</name>
<properties>
<java.version>1.8</java.version>
<maven.compiler.source>1.8</maven.compiler.source>
<maven.compiler.target>1.8</maven.compiler.target>
</properties>
<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId>
<exclusions>
<exclusion>
<groupId>org.junit.vintage</groupId>
<artifactId>junit-vintage-engine</artifactId>
</exclusion>
</exclusions>
</dependency>
</dependencies>
<build>
<!-- get all compiled class tests into source class -->
<testOutputDirectory>target/classes</testOutputDirectory>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
</plugin>
</plugins>
</build>
</project>
我需要执行什么来从命令行上构建的 jar 运行所有测试?
java -jar build-with-class-test-and-junit-in-it.jar # are there more parameters?
【问题讨论】:
标签: java spring-boot junit spring-test-mvc