相关疑难解决方法(0)

spring-boot testing - 多个测试可以共享一个上下文吗?

我创建了多个spring-boot测试类,(spring-boot 1.4.0).

FirstActionTest.java:

@RunWith(SpringRunner.class)
@WebMvcTest(FirstAction.class)
@TestPropertySource("classpath:test-application.properties")
public class FirstActionTest {
    @Autowired
    private MockMvc mvc;

    // ...
}
Run Code Online (Sandbox Code Playgroud)

SecondActionTest.java:

@RunWith(SpringRunner.class)
@WebMvcTest(SecondAction.class)
@TestPropertySource("classpath:test-application.properties")
public class SecondActionTest {
    @Autowired
    private MockMvc mvc;

    // ...
}
Run Code Online (Sandbox Code Playgroud)

运行测试时:

mvn测试

它似乎为每个测试类创建了一个弹簧测试上下文,我猜这是不必要的.

问题是:

  • 是否可以在多个测试类之间共享一个弹簧测试上下文,如果是,如何?

java spring spring-test spring-boot

14
推荐指数
1
解决办法
9004
查看次数

标签 统计

java ×1

spring ×1

spring-boot ×1

spring-test ×1