对于 dropwizard 来说非常陌生,我正在尝试“完全”创建一个集成测试,以他们为例:
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");
}
}
到目前为止有两个问题:首先,当我从 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
更改命令行选项以引用配置文件:../dev-config.yml
Edit:正如 @nightograph 评论的那样IntelliJ是右键单击项目文件夹并将目录标记为"Resources Root"
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)