集成测试的执行顺序在 Spring Boot 中不起作用(
The order of execution of integration tests does not work in Srping Boot (
我使用 Java 11(我不是在寻找 class.)
中方法的执行顺序
网站上没有回答我问题的帖子
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>2.4.1</version>
<relativePath/> <!-- lookup parent from repository -->
</parent>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.testcontainers</groupId>
<artifactId>junit-jupiter</artifactId>
<scope>test</scope>
</dependency>
@SpringBootTest(webEnvironment = SpringBootTest.WebEnvironment.RANDOM_PORT)
@Suite.SuiteClasses({TestFirst.class,
TestSecond.class,
AdminTest.class})
public class ApplicationTests {
}
public class TestFirst extends ApplicationTests {
@Test
void run(){
}
}
public class TestSecond extends ApplicationTests {
@Test
void run(){
}
}
public class AdminTest extends ApplicationTests {
@Test
void run(){
}
}
我使用注解@Suite.SuiteClasses.
我假设测试classes应该是运行一项一项的。未遵循启动顺序。每个 class 都位于自己的目录中。
对于Spring,这就像一个单独的集成测试。
如何让 classes 按照我定义的顺序执行?
也许还有另一种方法?
运行 测试顺序故意未定义。每个测试都应该设置它需要的资源并在之后进行清理。各个@Tests 运行 的顺序无关紧要。
您可以使用@Before 和@After 注释为每个测试做一些设置和清理。还有@BeforeAll 和@AfterAll 到setup/clean class 级别(它们在class 中执行before/after all/any 测试)。
原则是单元测试是完全独立的,可以运行独立于任何其他测试。您应该能够选择一个测试并 运行 它。
我使用 Java 11(我不是在寻找 class.)
中方法的执行顺序网站上没有回答我问题的帖子
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>2.4.1</version>
<relativePath/> <!-- lookup parent from repository -->
</parent>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.testcontainers</groupId>
<artifactId>junit-jupiter</artifactId>
<scope>test</scope>
</dependency>
@SpringBootTest(webEnvironment = SpringBootTest.WebEnvironment.RANDOM_PORT)
@Suite.SuiteClasses({TestFirst.class,
TestSecond.class,
AdminTest.class})
public class ApplicationTests {
}
public class TestFirst extends ApplicationTests {
@Test
void run(){
}
}
public class TestSecond extends ApplicationTests {
@Test
void run(){
}
}
public class AdminTest extends ApplicationTests {
@Test
void run(){
}
}
我使用注解@Suite.SuiteClasses.
我假设测试classes应该是运行一项一项的。未遵循启动顺序。每个 class 都位于自己的目录中。
对于Spring,这就像一个单独的集成测试。
如何让 classes 按照我定义的顺序执行?
也许还有另一种方法?
运行 测试顺序故意未定义。每个测试都应该设置它需要的资源并在之后进行清理。各个@Tests 运行 的顺序无关紧要。
您可以使用@Before 和@After 注释为每个测试做一些设置和清理。还有@BeforeAll 和@AfterAll 到setup/clean class 级别(它们在class 中执行before/after all/any 测试)。
原则是单元测试是完全独立的,可以运行独立于任何其他测试。您应该能够选择一个测试并 运行 它。