8

在开发 Web 应用程序时,SpringBoot 开发工具模块可以方便地加快编译和运行循环。但是,我找不到任何类似的集成测试功能。

更具体地说,假设我有一个集成测试(用@RunWith(SpringRunner.class)and注释@SpringBootTest),它在随机端口上启动一个 Web 服务器并测试一些 REST 端点。我想要一个交互式测试运行器,它不会在测试用例失败时终止进程。相反,它将等待代码中的更改,如果检测到更改,它将重新加载并重新运行测试(就像开发工具中的热交换一样)

我对这个功能的搜索没有成功,所以我想知道实现这个功能的最快方法是什么。考虑到 Springs 的受欢迎程度,为什么没有广为人知的方式来做到这一点?

编辑

在源代码中挖掘了一下,我发现了以下一段代码。

/**
 * Default {@link RestartInitializer} that only enable initial restart when running a
 * standard "main" method. Skips initialization when running "fat" jars (included
 * exploded) or when running from a test.
 *
 * @author Phillip Webb
 * @author Andy Wilkinson
 * @since 1.3.0
 */
public class DefaultRestartInitializer implements RestartInitializer {

    private static final Set<String> SKIPPED_STACK_ELEMENTS;

    static {
        Set<String> skipped = new LinkedHashSet<>();
        skipped.add("org.junit.runners.");
        skipped.add("org.junit.platform.");
        skipped.add("org.springframework.boot.test.");
        skipped.add("cucumber.runtime.");
        SKIPPED_STACK_ELEMENTS = Collections.unmodifiableSet(skipped);
    }
    ...

由此,我了解到作者明确禁用了对测试的支持。谁能解释一下?

4

0 回答 0