如何在 Dropwizard 的测试 class 中初始化包

How to initialize bundle in test class in Dropwizard

我正在使用 dropwizard,但现在卡住了。当我添加新的包时,它从其他来源给我数据,我的资源测试用例失败了,因为我现在不知道如何测试我的资源。我试过使用 mockito,但无论如何都行不通。

所以这是我的问题 - 如何在我的测试中初始化 bundle class 以便我的测试对象能够正确地从 bundle 中获取数据?或者您可能有其他解决方案来解决这个问题?

要测试 dropwizard 资源,请使用 dropwizard-testing 包。 有了这个,您可以定义 class 规则并启动您的测试上下文:

@ClassRule
public static final DropwizardAppRule<TestConfiguration> RULE =
        new DropwizardAppRule<TestConfiguration>(MyApp.class, "my-app-config.yaml");

您也可以使用 ResourceTestRule class.

在没有上下文的情况下测试资源