【问题标题】:BDD Jbehave stories while executing results in Pending在 Pending 中执行结果时 BDD Jbehave 故事
【发布时间】:2018-03-07 12:46:30
【问题描述】:

最近我开始使用 JBehave 开发 BDD。 到目前为止,如果我使用 maven 运行,我的 maven 项目正在成功构建。然后它进入故事文件,但没有进一步进行。

我尝试使用 junit 运行,但得到了相同的结果..

我认为我的问题在于执行程序文件。 我在许多网站甚至 Jbehave.org 和许多 stackoverflow 查询中进行了搜索..但徒劳无功 帮我解决这个问题...如果您需要任何其他信息,请告诉我

I spent so much time rectifying this.But couldn't able to find the solution.
Here is my runner file..
package runnerFile;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;

import org.jbehave.core.configuration.Configuration;
import org.jbehave.core.configuration.MostUsefulConfiguration;
import org.jbehave.core.io.CodeLocations;
import org.jbehave.core.io.LoadFromClasspath;
import org.jbehave.core.io.StoryFinder;
import org.jbehave.core.junit.JUnitStories;
import org.jbehave.core.junit.JUnitStory;
import org.jbehave.core.reporters.Format;
import org.jbehave.core.reporters.StoryReporterBuilder;
import org.jbehave.core.steps.InjectableStepsFactory;
import org.jbehave.core.steps.InstanceStepsFactory;
import org.jbehave.core.steps.ScanningStepsFactory;
import org.jbehave.core.steps.Steps;


public class TestRunner extends JUnitStories{ 
    @Override
    public Configuration configuration() { 
        return new MostUsefulConfiguration()                
                .useStoryLoader(
                        new LoadFromClasspath(this.getClass().getClassLoader()))
                .useStoryReporterBuilder(
                        new StoryReporterBuilder()
                            .withDefaultFormats()
                            .withFormats(Format.HTML, Format.CONSOLE)
                            .withRelativeDirectory("jbehave-report")
                );
    }

    @Override
    public InjectableStepsFactory stepsFactory() {
      //  ArrayList<Object> stepFileList = new ArrayList<Object>();
        ArrayList<Steps> stepFileList = new ArrayList<Steps>();
       stepFileList.add(new Steps(configuration()));
       return new InstanceStepsFactory(configuration(), stepFileList);
        //return new ScanningStepsFactory(configuration(), "org.jbehave.examples.core.steps", "my.other.steps"`enter code here` ).matchingNames(".*Steps").notMatchingNames(".*SkipSteps");     
    }

    @Override
    protected List<String> storyPaths() {
       return new StoryFinder().
               findPaths(CodeLocations.codeLocationFromClass(
                       this.getClass()), 
                       Arrays.asList("**/TC_2.story"), 
                       Arrays.asList(""));
}
}




I kept my story file inside src/test/resources . and step definition inside src/test/java

****story:****

**src/test/resources**

Narrative:
In order to communicate effectively to the business some functionality
As a development team
I want to use Behaviour-Driven Development

Scenario:  A scenario is a collection of executable steps of different type
Given I launch the url
When I login with username <Username> and password <Password>
Then I should see the homepage

Examples:
|Username|Password|
|test@gmail.com|test1234|

**stepDefinition**

**src/test/java:**


package definition;

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

import pages.Homepage_Pages;

public class HomePage {

    Homepage_Pages home;

    @Given("I launch the url")
    public void url()
    {
        home.launchUrl();
    }

    @When("I login with username <Username> and password <Password>")
    public void login(@Named("Username") String Username, @Named("Password") String Password)
    {
        System.out.println(Username);
    }

    @Then("I should see the homepage")
    public void homePageVerification()
    {
        System.out.println("Heello");
    }
}

Maven 控制台:

【问题讨论】:

  • 不要发布代码或控制台输出的屏幕截图。无法搜索它们,因此遇到您问题的其他人可能无法找到您的问题。
  • 下次会关注

标签: maven bdd jbehave


【解决方案1】:

试试下面的代码,这是一个精简的简单测试运行程序,它没有做任何花哨的事情,只是运行在主文件夹的子文件夹中找到的所有故事,并在定义步骤文件位置包含所有步骤类。我的原件有很多硬编码的东西,但我将它们更改为最终字符串,因此应该很容易替换您的情况并使用此文件运行。显然,将 "com.yourpackage.steps" 更改为您放置步骤文件的任何包文件夹。希望这会有所帮助。

package testrunner;

import java.io.File;
import java.util.ArrayList;
import java.util.List;

import org.jbehave.core.configuration.Configuration;
import org.jbehave.core.configuration.MostUsefulConfiguration;
import org.jbehave.core.embedder.EmbedderControls;
import org.jbehave.core.io.CodeLocations;
import org.jbehave.core.io.StoryFinder;
import org.jbehave.core.junit.JUnitStories;
import org.jbehave.core.reporters.CrossReference;
import org.jbehave.core.reporters.Format;
import org.jbehave.core.reporters.StoryReporterBuilder;
import org.jbehave.core.steps.InjectableStepsFactory;
import org.jbehave.core.steps.InstanceStepsFactory;
import org.junit.runner.RunWith;

import de.codecentric.jbehave.junit.monitoring.JUnitReportingRunner;

@RunWith(JUnitReportingRunner.class)
public class TestRunner extends JUnitStories {

    private Configuration configuration;

    public TestRunner() {

        super();

        CrossReference crossReference = new CrossReference();

        configuration = new MostUsefulConfiguration();

        configuration.useStoryReporterBuilder(
                new StoryReporterBuilder().withFormats(Format.HTML, Format.STATS, Format.CONSOLE)
                .withCodeLocation(CodeLocations.codeLocationFromPath("target/."))
                .withCrossReference(crossReference));

        EmbedderControls embedderControls = configuredEmbedder().embedderControls();

        embedderControls.doBatch(false);
        embedderControls.doGenerateViewAfterStories(true);
        embedderControls.doSkip(false);
        embedderControls.doVerboseFailures(true);
        embedderControls.doVerboseFiltering(true);
        embedderControls.useThreads(1);
        embedderControls.useStoryTimeouts("1800");

    }

    @Override
    protected List<String> storyPaths()
    {
        return new StoryFinder().findPaths(CodeLocations.codeLocationFromClass(this.getClass()), "**/*.story", "");
    }

    @Override
    public Configuration configuration() {
        return configuration;
    }

    @Override
    public InjectableStepsFactory stepsFactory() {

        final String stepsPackage = "com.yourpackage.steps";
        final String stepsLoc = "src/test/java/" + stepsPackage.replace(".", "/");

        List<Object> stepList = new ArrayList<Object>();

        File steps = new File(stepsLoc);
        File[] fileList = steps.listFiles();

        int size = fileList.length;

        for (int i = 0; i < size; i++) {

            if (fileList[i].isFile()) {                                     // also returns folders (directories)
                String value = fileList[i].getName().replace(".java", "");  // strip extensions
                if (!value.toLowerCase().contains("testrunner")) {          // ignore testrunner itself
                    try {
                        Object stepObject = Class.forName((stepsPackage + "." + value)).newInstance();
                        stepList.add(stepObject);
                    } catch (InstantiationException e) {
                        e.printStackTrace();
                    } catch (IllegalAccessException e) {
                        e.printStackTrace();
                    } catch (ClassNotFoundException e) {
                        e.printStackTrace();
                    }
                }
            }
        }
        return new InstanceStepsFactory(configuration(), stepList);
    }

}

【讨论】:

  • 生成报告视图到 '/Users/334750/eclipse-workspace/Sample/target/jbehave' 使用格式 '[html, stats, console, junitscenarioreporter]' 和视图属性 '{navigator=ftl/ jbehave-navigator.ftl,views=ftl/jbehave-views.ftl,reports=ftl/jbehave-reports.ftl,nonDecorated=ftl/jbehave-report-non-decorated.ftl,decorated=ftl/jbehave-report-decorated。 ftl, maps=ftl/jbehave-maps.ftl}' 报告视图生成 0 个故事(其中 0 个待定),包含 0 个场景(其中 0 个待定) java.lang.RuntimeException: java.lang.NullPointerException
  • 您是否将 testrunner 作为 JUnit 运行?您的模块,尤其是您的步骤类,是否设置在正确的文件夹中?您的步骤文件是在包下还是未命名包下?什么行和模块准确返回空指针异常?在您的原始帖子中发布堆栈跟踪。
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2011-09-07
  • 1970-01-01
  • 1970-01-01
  • 2011-05-02
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多