我在我的项目中使用jbehave
的故事:
Scenario: Basic new document creation
Given a user Micky Mouse
When new document created
Then document should named new document
And document status should be NEW
我代码:
/snip
@Then("document status should be $status")
public void documentStatusShouldBe(@Named("status") DocStatus status) {
System.out.println(activeDocument.getStatus());
assertThat(activeDocument.getStatus(), equalTo(status));
}
/snip
我的枚举:
public enum DocStatus {
NEW, IN_PROGRESS, APPROVE
}
当我做测试时,我得到:
org.jbehave.core.embedder。Embedder$ runningstoryesfailed:失败运行的故事:ReportsCount[故事= 1,storiesNotAllowed = 0, storiesPending = 0,场景= 1,scenariosFailed = 1, scenariosNotAllowed = 0, scenariosPending = 0, stepsFailed = 1)在org.jbehave.core.embedder.Embedder ThrowingRunningStoriesFailed.handleFailures美元(Embedder.java: 499)在org.jbehave.core.embedder.Embedder.handleFailures (Embedder.java: 265)在org.jbehave.core.embedder.Embedder.generateReportsView (Embedder.java: 252)在org.jbehave.core.embedder.Embedder.generateReportsView (Embedder.java: 233)在org.jbehave.core.embedder.Embedder.runStoriesAsPaths (Embedder.java: 212)运行(JUnitStory.java:24stories.DocStories.run (DocStories.java: 34)sun.reflect.NativeMethodAccessorImpl。invoke0(本机方法)atsun.reflect.NativeMethodAccessorImpl。调用(未知源)atsun.reflect.DelegatingMethodAccessorImpl。调用(未知源)atjava.lang.reflect.Method。调用(未知源)atorg.junit.runners.model.FrameworkMethod runreflectivecall 1.美元(FrameworkMethod.java: 44)在org.junit.internal.runners.model.ReflectiveCallable.run (ReflectiveCallable.java: 15)在org.junit.runners.model.FrameworkMethod.invokeExplosively (FrameworkMethod.java: 41)在org.junit.internal.runners.statements.InvokeMethod.evaluate (InvokeMethod.java: 20)在org.junit.runners.BlockJUnit4ClassRunner.runNotIgnored (BlockJUnit4ClassRunner.java: 79)在org.junit.runners.BlockJUnit4ClassRunner.runChild (BlockJUnit4ClassRunner.java: 71)在org.junit.runners.BlockJUnit4ClassRunner.runChild (BlockJUnit4ClassRunner.java: 49)在org.junit.runners.ParentRunner$3.run(ParentRunner.java:193) atorg.junit.runners.ParentRunner时间表(ParentRunner.java: 52) 1.美元org.junit.runners.ParentRunner.runChildren (ParentRunner.java: 191)org.junit.runners.ParentRunner.access 000美元(ParentRunner.java: 42)org.junit.runners.ParentRunner评估(ParentRunner.java: 184) 2.美元org.junit.runners.ParentRunner.run (ParentRunner.java: 236)org.eclipse.jdt.internal.junit4.runner.JUnit4TestReference.run (JUnit4TestReference.java: 50)在org.eclipse.jdt.internal.junit.runner.TestExecution.run (TestExecution.java: 38)在org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests (RemoteTestRunner.java: 467)在org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests (RemoteTestRunner.java: 683)在org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.run (RemoteTestRunner.java: 390)在org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.main (RemoteTestRunner.java: 197)
我做错了什么?
您的嵌入器(通常是故事类)需要显式地将EnumConverter添加到已知列表中:
configuration().useParameterConverters(
configuration().parameterConverters().addConverters(
new ParameterConverters.EnumConverter() ) );
JBehave默认不添加此转换器(参见ParmeterConverters.defaultConverters())