【问题标题】:Start services manually when doing a spring boot test在进行 Spring Boot 测试时手动启动服务
【发布时间】:2019-12-06 05:12:04
【问题描述】:

所以我有一个用 @SpringBootTest 注释的测试类

@SpringBootTest
@Slf4j
public class IntegrationTests {}

此代码会自动启动我的应用程序中的两个类,并使用@service 进行注释。
在我的集成测试中,我正在测试 spring 调度程序是否按预期工作并且测试通过了。

现在我想编写另一个测试,只测试使用@service 注释的两个服务之一。我要启用和禁用自己的第二个服务。这是因为两个服务之一使用了springboot的@scheduled注解,这导致了不可预知的逻辑。

那么有没有一种方法可以让我启动 @SpringBootTest 并选择我需要的服务?

提前致谢!

【问题讨论】:

  • 请看here
  • 是自动装配需要的并模拟不需要的

标签: spring-boot spring-boot-test


【解决方案1】:

您是否尝试在@SpringBootTest 中添加测试类?像这样: @SpringBootTest(classes = YourTestClass.class)

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2021-05-20
    • 1970-01-01
    • 2018-08-06
    • 2019-03-17
    • 2017-09-03
    • 1970-01-01
    • 2016-06-15
    相关资源
    最近更新 更多