如何在 Intellij 中为单元测试指定 Dropwizard 配置文件?
How do I specify the Dropwizard config file in Intellij for unit tests?
我正在 Dropwizard 0.9 中开发一个应用程序,使用 IntelliJ Idea 作为我的 IDE。我配置了一个 运行 配置,它通过命令行参数 "server ./path/to/config.yml" 将配置文件指定为 运行 with.
但是,当我尝试 运行 我的单元测试时,我无法确定如何将此配置文件路径传递给服务器。 Run/Debug 配置对话框有一个 "Program Arguments" 字段,但它被永久禁用(并且它旁边的编辑按钮没有任何作用)。
如何启用程序参数,或者,是否有另一种方法来指定用于测试的配置文件?
如果您的 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);
我正在 Dropwizard 0.9 中开发一个应用程序,使用 IntelliJ Idea 作为我的 IDE。我配置了一个 运行 配置,它通过命令行参数 "server ./path/to/config.yml" 将配置文件指定为 运行 with.
但是,当我尝试 运行 我的单元测试时,我无法确定如何将此配置文件路径传递给服务器。 Run/Debug 配置对话框有一个 "Program Arguments" 字段,但它被永久禁用(并且它旁边的编辑按钮没有任何作用)。
如何启用程序参数,或者,是否有另一种方法来指定用于测试的配置文件?
如果您的 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);