gpt4 book ai didi

intellij-idea - 如何在 Intellij 中为单元测试指定 Dropwizard 配置文件?

转载 作者:行者123 更新时间:2023-12-04 06:01:52 24 4
gpt4 key购买 nike

我正在 Dropwizard 0.9 中开发一个应用程序,使用 IntelliJ Idea 作为我的 IDE。我配置了一个运行配置,它传递命令行参数“server ./path/to/config.yml”来指定要运行的配置文件。

但是,当我尝试运行单元测试时,我无法确定如何将此配置文件路径传递给服务器。运行/调试配置对话框有一个“程序参数”字段,但它被永久禁用(并且它旁边的编辑按钮什么都不做)。

我如何启用程序参数,或者,是否有另一种方法来指定测试的配置文件?

最佳答案

如果您的 config.yml 在项目的根文件夹中,只需在 IDE 中设置 server config.yml。看看这个video .

如果您想从项目的根文件夹访问 config.yml,只需将文件名传递给规则即可。

@ClassRule
public static final DropwizardAppRule<DWGettingStartedConfiguration> RULE
= new DropwizardAppRule<>(DWGettingStartedApplication.class,
"config.yml");

此外,可以将集成测试的配置文件存储在 src/test/resources 文件夹中。在这种情况下,可以使用以下代码访问该文件:

/**
* A path to test configuration file.
*/
private static final String CONFIG_PATH
= ResourceHelpers.resourceFilePath("test-config.yml");
/**
* Start the application before all test methods.
*/
@ClassRule
public static final DropwizardAppRule<DropBookmarksConfiguration> RULE
= new DropwizardAppRule<>(
DropBookmarksApplication.class,
CONFIG_PATH);

此外,请看一下我的示例项目here , herehere .

关于intellij-idea - 如何在 Intellij 中为单元测试指定 Dropwizard 配置文件?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/40295165/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com