JBehave RunningStoriesFailed异常; org.jbehave.core.embedder.Embedder $ RunningStoriesFailed

时间:2018-03-08 10:12:46

标签: jbehave

执行项目时出现此错误: -

java.lang.RuntimeException: org.jbehave.core.embedder.Embedder$RunningStoriesFailed: Failures in running stories: 
sample/test.story: org.jbehave.core.embedder.StoryManager$StoryExecutionFailed: sample/test.story
    at net.serenitybdd.jbehave.runners.SerenityReportingRunner.run(SerenityReportingRunner.java:169)
    at org.junit.runner.JUnitCore.run(JUnitCore.java:137)
    at com.intellij.junit4.JUnit4IdeaTestRunner.startRunnerWithArgs(JUnit4IdeaTestRunner.java:68)
    at com.intellij.rt.execution.junit.IdeaTestRunner$Repeater.startRunnerWithArgs(IdeaTestRunner.java:47)
    at com.intellij.rt.execution.junit.JUnitStarter.prepareStreamsAndStart(JUnitStarter.java:242)
    at com.intellij.rt.execution.junit.JUnitStarter.main(JUnitStarter.java:70)
Caused by: org.jbehave.core.embedder.Embedder$RunningStoriesFailed: Failures in running stories: 
sample/test.story: org.jbehave.core.embedder.StoryManager$StoryExecutionFailed: sample/test.story
    at org.jbehave.core.embedder.Embedder$ThrowingRunningStoriesFailed.handleFailures(Embedder.java:553)
    at org.jbehave.core.embedder.Embedder.handleFailures(Embedder.java:238)
    at org.jbehave.core.embedder.Embedder.runStoriesAsPaths(Embedder.java:216)
    at net.serenitybdd.jbehave.embedders.ExtendedEmbedder.runStoriesAsPaths(ExtendedEmbedder.java:60)
    at net.serenitybdd.jbehave.runners.SerenityReportingRunner.run(SerenityReportingRunner.java:167)
    ... 5 more
test.story :-
Meta:

Narrative:
As a user
I want to perform an action
So that I can achieve a business goal

Scenario: scenario description

Given a variable <var>

When save the variable <var>

Then display the variable

Examples:
|var|
|test|
package sample;

import org.jbehave.core.annotations.Given;
import org.jbehave.core.annotations.Then;
import org.jbehave.core.annotations.When;

import net.thucydides.core.annotations.Steps;

public class SampleScenario {

  @Steps
  private SampleBehaviour sampleBehaviour;

  @Given("a variable <var>")
  public void checkVar(String var){
    sampleBehaviour.checkVariable(var);
  }

  @When("save the variable <var>")
  public void setVar(String var){
    sampleBehaviour.setVariable(var);
  }

  @Then("display the variable")
  public void printVar(){
    sampleBehaviour.printVar();
  }

}


-----------------------------------------------------------------

package sample;

import net.thucydides.core.annotations.Step;
import net.thucydides.core.steps.ScenarioSteps;

public class SampleBehaviour extends ScenarioSteps {

  private String variable;

  @Step public void checkVariable(String var) {
    if (var == null) {
      System.out.println("var is not valid");
    }
  }

  @Step public void setVariable(String var) {
    variable = var;
  }

  @Step public void printVar() {
    System.out.println("var = " + variable);
  }
}


------------------------------------------------------------------


package testsuite;

import java.util.ArrayList;
import java.util.List;
import org.jbehave.core.annotations.BeforeStories;
import com.gdn.qa.util.restassured.HttpHeaderManager;
import com.gdn.qa.util.restassured.UserDefinedVariables;

import net.serenitybdd.jbehave.SerenityStories;

public class AcceptanceTestSuite extends SerenityStories {

  @BeforeStories
  public void initApi(){
    UserDefinedVariables.initDataUserDefinedVariables();
    HttpHeaderManager.addHeader("Content-Type","application/json");
    HttpHeaderManager.addHeader("Charset","UTF-8");
  }


  @Override
  public List<String> storyPaths(){
    List<String> testLink = new ArrayList<>();
    testLink.add("sample/test.story");
    return testLink;
  }
}

1 个答案:

答案 0 :(得分:0)

在将我的jbehave-core依赖关系从旧版本3.10更新到4.5.1之后,没有更新jbehave-junit-runner,我遇到了类似的问题。

在更新之前,我有两个主要依赖项:

    <dependency>
        <groupId>org.jbehave</groupId>
        <artifactId>jbehave-core</artifactId>
        <version>3.10</version>
    </dependency>
    <dependency>
        <groupId>de.codecentric</groupId>
        <artifactId>jbehave-junit-runner</artifactId>
        <version>1.2.0</version>
    </dependency>

仅更新jbeave-core后,测试已损坏:

    <dependency>
        <groupId>org.jbehave</groupId>
        <artifactId>jbehave-core</artifactId>
        <version>4.5.1</version>
    </dependency>
    <dependency>
        <groupId>de.codecentric</groupId>
        <artifactId>jbehave-junit-runner</artifactId>
        <version>1.2.0</version>
    </dependency>

我必须按照以下步骤更新到新版本的jbehave-junit-runner:

    <dependency>
        <groupId>org.jbehave</groupId>
        <artifactId>jbehave-core</artifactId>
        <version>4.5.1</version>
    </dependency>
    <dependency>
        <groupId>com.github.valfirst</groupId>
        <artifactId>jbehave-junit-runner</artifactId>
        <version>2.3.0</version>
    </dependency>

此问题已解决。