我已配置了Jbehave测试项目,并在项目中有一个.story文件。我尝试使用我在互联网上找到的配置设置但是当我运行测试时,它给了我一个错误,堆栈跟踪如下所示
org.jbehave.core.io.StoryResourceNotFound: Story path 'D:\AutoRegression8.8\NewProject\src\BusinessCase1.story' not found by class loader sun.misc.Launcher$AppClassLoader@631d75b9
at org.jbehave.core.io.LoadFromClasspath.resourceAsStream(LoadFromClasspath.java:80)
at org.jbehave.core.io.LoadFromClasspath.loadResourceAsText(LoadFromClasspath.java:65)
at org.jbehave.core.io.LoadFromClasspath.loadStoryAsText(LoadFromClasspath.java:74)
at org.jbehave.core.embedder.PerformableTree.storyOfPath(PerformableTree.java:261)
at org.jbehave.core.embedder.StoryManager.storyOfPath(StoryManager.java:61)
at org.jbehave.core.embedder.StoryManager.storiesOf(StoryManager.java:92)
at org.jbehave.core.embedder.StoryManager.runStoriesAsPaths(StoryManager.java:86)
at org.jbehave.core.embedder.Embedder.runStoriesAsPaths(Embedder.java:213)
at org.jbehave.core.junit.JUnitStories.run(JUnitStories.java:20)
at TestRunner.run(TestRunner.java:59)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:606)
at org.junit.runners.model.FrameworkMethod$1.runReflectiveCall(FrameworkMethod.java:47)
at org.junit.internal.runners.model.ReflectiveCallable.run(ReflectiveCallable.java:12)
at org.junit.runners.model.FrameworkMethod.invokeExplosively(FrameworkMethod.java:44)
at org.junit.internal.runners.statements.InvokeMethod.evaluate(InvokeMethod.java:17)
at org.junit.runners.ParentRunner.runLeaf(ParentRunner.java:271)
at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:70)
at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:50)
at org.junit.runners.ParentRunner$3.run(ParentRunner.java:238)
at org.junit.runners.ParentRunner$1.schedule(ParentRunner.java:63)
at org.junit.runners.ParentRunner.runChildren(ParentRunner.java:236)
at org.junit.runners.ParentRunner.access$000(ParentRunner.java:53)
at org.junit.runners.ParentRunner$2.evaluate(ParentRunner.java:229)
at org.junit.runners.ParentRunner.run(ParentRunner.java:309)
at org.eclipse.jdt.internal.junit4.runner.JUnit4TestReference.run(JUnit4TestReference.java:50)
at org.eclipse.jdt.internal.junit.runner.TestExecution.run(TestExecution.java:38)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:459)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:675)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.run(RemoteTestRunner.java:382)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.main(RemoteTestRunner.java:192)
但是,我的.story文件位于代码尝试找到它的同一位置。要查找.story文件,我使用了以下代码:
@Override
protected List<String> storyPaths() {
/*
* return new StoryFinder().findPaths(
* CodeLocations.codeLocationFromClass(this.getClass()), "**.story",
* "");
*/
String placetoSearch = System.getProperty("user.dir") + "\\src\\BusinessCase1.story";
/*return new StoryFinder().findPaths(CodeLocations.codeLocationFromClass(this.getClass()), placetoSearch, "");*/
return Arrays
.asList(placetoSearch);
}
在这方面的任何帮助或参考将不胜感激。
答案 0 :(得分:1)
寻找文件和寻找资源之间存在差异。
JBehave使用您设置的类加载器来查找作为资源的故事。资源通常是您正在运行的软件包的一部分。这意味着它需要一个相对于类根的文件名,而不是绝对路径。
(如果您使用的是myClass.getResource()
而不是myClassLoader.getResource()
,那么它将与您的班级相关。)
如果您愿意,也可以使用unix样式斜杠。请尝试"/BusinessCase1.story"
作为文件名。