Dropwizard 集成测试找不到资源文件
Dropwizard integration test cannot find resource file
对 dropwizard 很陌生,我正在尝试创建一个集成测试 "exactly" 他们如何将其作为示例:
https://dropwizard.github.io/dropwizard/manual/testing.html
public class LoginAcceptanceTest {
@ClassRule
public static final DropwizardAppRule<TestConfiguration> RULE =
new DropwizardAppRule<TestConfiguration>(MyApp.class, ResourceHelpers.resourceFilePath("dev-config.yml"));
@Test
public void loginHandlerRedirectsAfterPost() {
//Client client = new JerseyClientBuilder(RULE.getEnvironment()).build("test client");
}
}
到目前为止有 2 个问题:首先,当我 运行 来自 intellij 的测试失败时,出现以下异常:
Caused by: java.lang.IllegalArgumentException: resource dev-config.yml not found.
完整的堆栈跟踪:
java.lang.ExceptionInInitializerError
at sun.misc.Unsafe.ensureClassInitialized(Native Method)
at sun.reflect.UnsafeFieldAccessorFactory.newFieldAccessor(UnsafeFieldAccessorFactory.java:43)
at sun.reflect.ReflectionFactory.newFieldAccessor(ReflectionFactory.java:140)
at java.lang.reflect.Field.acquireFieldAccessor(Field.java:1057)
at java.lang.reflect.Field.getFieldAccessor(Field.java:1038)
at java.lang.reflect.Field.get(Field.java:379)
at org.junit.runners.model.FrameworkField.get(FrameworkField.java:73)
at org.junit.runners.model.TestClass.getAnnotatedFieldValues(TestClass.java:230)
at org.junit.runners.ParentRunner.classRules(ParentRunner.java:255)
at org.junit.runners.ParentRunner.withClassRules(ParentRunner.java:244)
at org.junit.runners.ParentRunner.classBlock(ParentRunner.java:194)
at org.junit.runners.ParentRunner.run(ParentRunner.java:362)
at org.junit.runner.JUnitCore.run(JUnitCore.java:137)
at com.intellij.junit4.JUnit4IdeaTestRunner.startRunnerWithArgs(JUnit4IdeaTestRunner.java:74)
at com.intellij.rt.execution.junit.JUnitStarter.prepareStreamsAndStart(JUnitStarter.java:211)
at com.intellij.rt.execution.junit.JUnitStarter.main(JUnitStarter.java:67)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
at com.intellij.rt.execution.application.AppMain.main(AppMain.java:134)
Caused by: java.lang.RuntimeException: java.lang.IllegalArgumentException: resource dev-config.yml not found.
at io.dropwizard.testing.ResourceHelpers.resourceFilePath(ResourceHelpers.java:23)
at com.amplify.ckla.resources.TeacherConfigResourceIntegrationTest.<clinit>(TeacherConfigResourceIntegrationTest.java:12)
... 21 more
Caused by: java.lang.IllegalArgumentException: resource dev-config.yml not found.
at com.google.common.base.Preconditions.checkArgument(Preconditions.java:145)
at com.google.common.io.Resources.getResource(Resources.java:197)
at io.dropwizard.testing.ResourceHelpers.resourceFilePath(ResourceHelpers.java:21)
... 22 more
dev-config.yml 肯定存在:
ls -a
. .idea build.sh pom.xml
.. CKLA.iml dev-config.yml src
.git README.md target
.gitignore develop.sh
将程序的 运行 目录更改为项目的根目录(具有 ls -a
命令输出的目录)。目前您很可能正在 运行 从 ./target
目录中安装它。
或者如果您从 .target
want/need 到 运行 更改命令行选项以将配置文件引用到:../dev-config.yml
编辑:
正如@nightograph 评论的那样,在 IntelliJ 中要做的确切事情是右键单击项目文件夹并将目录标记为 "Resources Root"
对 dropwizard 很陌生,我正在尝试创建一个集成测试 "exactly" 他们如何将其作为示例:
https://dropwizard.github.io/dropwizard/manual/testing.html
public class LoginAcceptanceTest {
@ClassRule
public static final DropwizardAppRule<TestConfiguration> RULE =
new DropwizardAppRule<TestConfiguration>(MyApp.class, ResourceHelpers.resourceFilePath("dev-config.yml"));
@Test
public void loginHandlerRedirectsAfterPost() {
//Client client = new JerseyClientBuilder(RULE.getEnvironment()).build("test client");
}
}
到目前为止有 2 个问题:首先,当我 运行 来自 intellij 的测试失败时,出现以下异常:
Caused by: java.lang.IllegalArgumentException: resource dev-config.yml not found.
完整的堆栈跟踪:
java.lang.ExceptionInInitializerError
at sun.misc.Unsafe.ensureClassInitialized(Native Method)
at sun.reflect.UnsafeFieldAccessorFactory.newFieldAccessor(UnsafeFieldAccessorFactory.java:43)
at sun.reflect.ReflectionFactory.newFieldAccessor(ReflectionFactory.java:140)
at java.lang.reflect.Field.acquireFieldAccessor(Field.java:1057)
at java.lang.reflect.Field.getFieldAccessor(Field.java:1038)
at java.lang.reflect.Field.get(Field.java:379)
at org.junit.runners.model.FrameworkField.get(FrameworkField.java:73)
at org.junit.runners.model.TestClass.getAnnotatedFieldValues(TestClass.java:230)
at org.junit.runners.ParentRunner.classRules(ParentRunner.java:255)
at org.junit.runners.ParentRunner.withClassRules(ParentRunner.java:244)
at org.junit.runners.ParentRunner.classBlock(ParentRunner.java:194)
at org.junit.runners.ParentRunner.run(ParentRunner.java:362)
at org.junit.runner.JUnitCore.run(JUnitCore.java:137)
at com.intellij.junit4.JUnit4IdeaTestRunner.startRunnerWithArgs(JUnit4IdeaTestRunner.java:74)
at com.intellij.rt.execution.junit.JUnitStarter.prepareStreamsAndStart(JUnitStarter.java:211)
at com.intellij.rt.execution.junit.JUnitStarter.main(JUnitStarter.java:67)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
at com.intellij.rt.execution.application.AppMain.main(AppMain.java:134)
Caused by: java.lang.RuntimeException: java.lang.IllegalArgumentException: resource dev-config.yml not found.
at io.dropwizard.testing.ResourceHelpers.resourceFilePath(ResourceHelpers.java:23)
at com.amplify.ckla.resources.TeacherConfigResourceIntegrationTest.<clinit>(TeacherConfigResourceIntegrationTest.java:12)
... 21 more
Caused by: java.lang.IllegalArgumentException: resource dev-config.yml not found.
at com.google.common.base.Preconditions.checkArgument(Preconditions.java:145)
at com.google.common.io.Resources.getResource(Resources.java:197)
at io.dropwizard.testing.ResourceHelpers.resourceFilePath(ResourceHelpers.java:21)
... 22 more
dev-config.yml 肯定存在:
ls -a
. .idea build.sh pom.xml
.. CKLA.iml dev-config.yml src
.git README.md target
.gitignore develop.sh
将程序的 运行 目录更改为项目的根目录(具有 ls -a
命令输出的目录)。目前您很可能正在 运行 从 ./target
目录中安装它。
或者如果您从 .target
want/need 到 运行 更改命令行选项以将配置文件引用到:../dev-config.yml
编辑:
正如@nightograph 评论的那样,在 IntelliJ 中要做的确切事情是右键单击项目文件夹并将目录标记为 "Resources Root"