Coder Social home page Coder Social logo

valfirst / jbehave-junit-runner Goto Github PK

View Code? Open in Web Editor NEW
72.0 103.0 53.0 1.73 MB

Integrate JBehave better with JUnit. Reports all Stories, Scenarios and Steps as JUnit Suites and Test Cases.

License: MIT License

Java 93.25% Gherkin 6.75%
jbehave junit4 junit hacktoberfest

jbehave-junit-runner's Introduction

JBehave JUnit Integration

jbehave-junit-runner CI Coverage Status Quality Gate Codacy Badge Maven Central Javadocs Known Vulnerabilities MIT licensed FOSSA Status

This little project is designed to make JBehave stories & scenarios show up in the JUnit view in Eclipse and potentially other IDEs that support custom test runners.

Installation

The project consists of only a handful of classes and is easy to use.

Using Maven

The easiest way is to include it in your acceptance test project(s) by ways of a Maven dependency. Binary, Sources and Javadocs are all available from Maven Central.

<dependency>
    <groupId>com.github.valfirst</groupId>
    <artifactId>jbehave-junit-runner</artifactId>
    <version>2.3.2</version>
</dependency>

Note that the JBehave library is set to scope provided in the POM, because any project using this Runner will naturally have their own version of JBehave already.

Current development SNAPSHOT versions are available from Sonatype's Nexus for Open Source projects.

Without Maven

If you cannot or do not want to use Maven, just add the library to your classpath.

Also make sure you add the dependencies of this library to the classpath as well. They can be seen in the pom.xml. For convenience, they are listed here, too:

  • jbehave-core (4.1+)
  • junit (4.12)

Your project will of course have JBehave already, just make sure it is version 4.1 or above.

Usage

Once it is on your classpath, the runner can be used to visualize the structure and the successes/failures of your JBehave acceptance tests.

Enabling

You will probably already have one or more classes that extend the default JBehave JUnitStories class. Just add this annotation:

@RunWith(JUnitReportingRunner.class)
public class MyAcceptanceTests extends JUnitStories {
    ...
}

Usually, this is everything you have to do. If you want to, you can use a little helper method to configure the configured Embedder so that it works nicely together with the JUnitReportingRunner.

JUnitReportingRunner.recommendedControls(configuredEmbedder());

This tells JBehave to use only one thread, and don't throw any exceptions when generating views or otherwise wrapping the execution up. This would confuse JUnit considerably, rendering the AfterStories Suite incomplete.

Caveats

There are a few issues you might encounter upon first installation and integration into your project. To alleviate these, the following are a few common pitfalls.

java.lang.NoSuchMethodException: ...storyPaths()

If you run into problems like this

java.lang.NoSuchMethodException: MyAcceptanceTests.storyPaths()
    at java.lang.Class.getDeclaredMethod(Class.java:1937)
    at org.jbehave.scenario.finegrained.junit.monitoring.JUnitReportingRunner.<init>(JUnitReportingRunner.java:33)
    at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
    at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:39)
    at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:27)
    at java.lang.reflect.Constructor.newInstance(Constructor.java:513)
    at org.junit.internal.builders.AnnotatedBuilder.buildRunner(AnnotatedBuilder.java:31)
    ....

you are likely extending a custom base class which was probably introduced to provide some common methods for all your test classes. This is perfectly fine, however in case you pulled up the storyPaths() method into that common base class, you

  1. either need to make it public OR
  2. override it in all descendants of that base class (just calling the super implementation is fine).

This is due to a reflection issue and might be fixed in future versions.

java.lang.NoSuchMethodError: org.junit.runner.Description.createSuiteDescription

If you see JUnit throw an error soon after a test starts, that looks like this

java.lang.NoSuchMethodError: org.junit.runner.Description.createSuiteDescription(Ljava/lang/String;[Ljava/lang/annotation/Annotation;)Lorg/junit/runner/Description;
    at de.codecentric.jbehave.junit.monitoring.JUnitDescriptionGenerator.createDescriptionFrom(JUnitDescriptionGenerator.java:43)
    at de.codecentric.jbehave.junit.monitoring.JUnitReportingRunner.buildDescriptionFromStories(JUnitReportingRunner.java:152)
    at de.codecentric.jbehave.junit.monitoring.JUnitReportingRunner.<init>(JUnitReportingRunner.java:73)
    at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
    ...

you most probably have an old version of JUnit on your classpath that does not have that method signature yet. Verify that you are using a recent version of JUnit and that it is not hidden by an older version which might hide it by being declared first on the classpath.

Example output

Once you are all set, you use the regular Run As -> JUnit Test command in Eclipse. The JUnit view should appear and display something like this:

Screenshot

Reporting Issues

In case you run into problems or have ideas on how to improve this piece of software, please do not hesitate to open an issue in the issue tracker, here on GitHub.

To make things easier (and quicker) for yourself (and us), please provide the following pieces of information in your ticket:

  • The version you are using (e. g. "1.0.0" or "1.0.1-SNAPSHOT as of 2012-05-25")
  • If possible, a stack trace of the error.
  • Ideally, a limited test case that allows us to reproduce the problem locally. This is indeed the best way to get a bug fixed quickly, because we'll have something specific to work on.
  • Any information about your environment that might be helpful, e. g. your JBehave version, which operating system, etc.

It might also be a good idea to try, if your particular problem has been fixed already in the latest snapshot release.

And, of course, we'd also very much appreciate pull requests for fixes that you have already made yourself. After all, this is where open source shines most :)

Credits

This project is based on the original implementation by Mark Burnett, located at http://code.google.com/p/jbehave-junit-monitor/ which worked with earlier versions of JBehave.

License

FOSSA Status

jbehave-junit-runner's People

Contributors

andreasek avatar andreiserea avatar avh4 avatar blackdark avatar bripkens avatar britter avatar cliviu avatar codacy-badger avatar dependabot-preview[bot] avatar dependabot-support avatar dependabot[bot] avatar dschneller avatar flozano avatar fossabot avatar hrflorianhoffmann avatar ibachyla avatar joshiste avatar jsedlace avatar lgtm-com[bot] avatar schmidtl avatar skurlow avatar soezen avatar stentrup avatar uarlouski avatar unelsry avatar valfirst avatar visusnet avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

jbehave-junit-runner's Issues

How to use with annotated runners

I am currently using a guice annotated path runner, which means that the @RunWith annotation is already used, is there a way to somehow chain this together or would it be necessary to write a guice reporting runner?

I tried this with v1.0.1.

jbehave-junit-runner requires causes Selenium WebDriver based tests to fail when Spring @Autowired

Another issue for the troubleshooting section.

JBehave Steps that make use Selenium WebDriver will fail because jbehave-junit-runner will cause the test to instantiate a WebDriver before it is required.

One workaround is to create a WebDriver Proxy/Wrapper that will delay the instantiation of the target Selenium WebDriver until it is really necessary.

For example:

public class WebDriverProxy implements WebDriver, JavascriptExecutor {

@SuppressWarnings("rawtypes")
private final Class webDriverClass;
private WebDriver driver;

@SuppressWarnings("rawtypes")
public WebDriverProxy(final Class webDriverClass) {
    this.webDriverClass = webDriverClass;
}

public WebDriver getDriver() {
    if (this.driver == null) {
        try {
            this.driver = (WebDriver) this.webDriverClass.newInstance();
        }
        catch (final InstantiationException e) {
            e.printStackTrace();
        }
        catch (final IllegalAccessException e) {
            e.printStackTrace();
        }
    }

    return this.driver;
}

@PreDestroy
public void clean() {
    quit();
}

public void get(final String url) {
    getDriver().get(url);
}

public String getCurrentUrl() {
    return getDriver().getCurrentUrl();
}

public String getTitle() {
    return getDriver().getTitle();
}

public List<WebElement> findElements(final By by) {
    return getDriver().findElements(by);
}

public WebElement findElement(final By by) {
    return getDriver().findElement(by);
}

public String getPageSource() {
    return getDriver().getPageSource();
}

public void close() {
    getDriver().close();
}

public void quit() {
    getDriver().quit();
}

public Set<String> getWindowHandles() {
    return getDriver().getWindowHandles();
}

public String getWindowHandle() {
    return getDriver().getWindowHandle();
}

public TargetLocator switchTo() {
    return getDriver().switchTo();
}

public Navigation navigate() {
    return getDriver().navigate();
}

public Options manage() {
    return getDriver().manage();
}

public Object executeScript(final String script, final Object... args) {
    return ((JavascriptExecutor) getDriver()).executeScript(script, args);
}

public Object executeAsyncScript(final String script, final Object... args) {
    return ((JavascriptExecutor) getDriver()).executeAsyncScript(script, args);
}

}

and configure it in Spring:

<bean id="webDriver" class="com.foo.WebDriverProxy">
    <constructor-arg value="org.openqa.selenium.firefox.FirefoxDriver"/>
</bean>

then use it in your JBehave Steps:

@Component("fooSteps")
public class FooSteps {

    @Autowired
    private WebDriver driver;

    ...
}

Create an example on how to inject members into a test using spring

We had quite a few requests on how to use the jbehave-junit-runner together with spring. The problem is, that both, our library and spring test provide a JUnitRunner and only one runner can be declared per test.

We should document a way to inject members into a jbehave junit test using spring. The easiest way would probably be, to create an ApplicationContext in the @Before hock by hand, get an AutowireCapableFactoryBean from there and then call autowireBean(Object)passing in the this reference (see also: http://stackoverflow.com/questions/3813588/how-to-inject-dependencies-into-a-self-instantiated-object-in-spring).

Review versions and scopes of dependencies

We shouldn't force dependencies on our clients, that are not absolutely necessary. For example we have the dependency to mockito defined in scope compile, although we're only using it in our test code.

NPE when getting the Story on CrossReference.java (story not setup for CrossReference)

To reproduce:
Have a class extending JUnitStories with the following configuration:

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

    public AwesomeNameStories() {
        CrossReference crossReference = new CrossReference().withJsonOnly().withOutputAfterEachStory(true)
                .excludingStoriesWithNoExecutedScenarios(true);
        ContextView contextView = new LocalFrameContextView().sized(640, 120);
        SeleniumContext seleniumContext = new SeleniumContext();
        SeleniumStepMonitor stepMonitor = new SeleniumStepMonitor(contextView, seleniumContext,
                crossReference.getStepMonitor());
        Format[] formats = new Format[] { new SeleniumContextOutput(seleniumContext), CONSOLE, WEB_DRIVER_HTML };
        StoryReporterBuilder reporterBuilder = new StoryReporterBuilder()
                .withCodeLocation(codeLocationFromClass(AwesomeNameStories.class)).withFailureTrace(true)
                .withFailureTraceCompression(true).withDefaultFormats().withFormats(formats)
                .withCrossReference(crossReference);

        Configuration configuration = new SeleniumConfiguration().useSeleniumContext(seleniumContext)
                .useFailureStrategy(new FailingUponPendingStep())
                .useStoryControls(new StoryControls().doResetStateBeforeScenario(false)).useStepMonitor(stepMonitor)
                .useStoryLoader(new LoadFromClasspath(AwesomeNameStories.class))
                .useStoryReporterBuilder(reporterBuilder);
        useConfiguration(configuration);

        ApplicationContext context = new SpringApplicationContextFactory("vipmgr-steps.xml").createApplicationContext();
        useStepsFactory(new SpringStepsFactory(configuration, context));
    }

When you run you'll get the following stack trace:

java.lang.NullPointerException: story not setup for CrossReference
                at org.jbehave.core.reporters.CrossReference$XRefStepMonitor.stepMatchesPattern(CrossReference.java:228)
                at org.jbehave.core.steps.DelegatingStepMonitor.stepMatchesPattern(DelegatingStepMonitor.java:25)
                at org.jbehave.core.steps.StepCandidate.matches(StepCandidate.java:135)
                at de.codecentric.jbehave.junit.monitoring.JUnitDescriptionGenerator.addSteps(JUnitDescriptionGenerator.java:97)
                at de.codecentric.jbehave.junit.monitoring.JUnitDescriptionGenerator.addScenarioSteps(JUnitDescriptionGenerator.java:90)
                at de.codecentric.jbehave.junit.monitoring.JUnitDescriptionGenerator.insertDescriptionForExamples(JUnitDescriptionGenerator.java:84)
                at de.codecentric.jbehave.junit.monitoring.JUnitDescriptionGenerator.createDescriptionFrom(JUnitDescriptionGenerator.java:50)
                at de.codecentric.jbehave.junit.monitoring.JUnitDescriptionGenerator.createDescriptionFrom(JUnitDescriptionGenerator.java:38)
                at de.codecentric.jbehave.junit.monitoring.JUnitReportingRunner.buildDescriptionFromStories(JUnitReportingRunner.java:100)
                at de.codecentric.jbehave.junit.monitoring.JUnitReportingRunner.<init>(JUnitReportingRunner.java:57)
                at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
                at sun.reflect.NativeConstructorAccessorImpl.newInstance(Unknown Source)
                at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(Unknown Source)
                at java.lang.reflect.Constructor.newInstance(Unknown Source)
                at org.junit.internal.builders.AnnotatedBuilder.buildRunner(AnnotatedBuilder.java:31)
                at org.junit.internal.builders.AnnotatedBuilder.runnerForClass(AnnotatedBuilder.java:24)
                at org.junit.runners.model.RunnerBuilder.safeRunnerForClass(RunnerBuilder.java:57)
                at org.junit.internal.builders.AllDefaultPossibilitiesBuilder.runnerForClass(AllDefaultPossibilitiesBuilder.java:29)
                at org.junit.runners.model.RunnerBuilder.safeRunnerForClass(RunnerBuilder.java:57)
                at org.junit.internal.requests.ClassRequest.getRunner(ClassRequest.java:24)
                at org.eclipse.jdt.internal.junit4.runner.JUnit4TestReference.<init>(JUnit4TestReference.java:33)
                at org.eclipse.jdt.internal.junit4.runner.JUnit4TestClassReference.<init>(JUnit4TestClassReference.java:25)
                at org.eclipse.jdt.internal.junit4.runner.JUnit4TestLoader.createTest(JUnit4TestLoader.java:48)
                at org.eclipse.jdt.internal.junit4.runner.JUnit4TestLoader.loadTests(JUnit4TestLoader.java:38)
                at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:452)
                at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:683)
                at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.run(RemoteTestRunner.java:390)
                at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.main(RemoteTestRunner.java:197)

Seems like when calling CrossReference.stepMatchesPattern(), the call to
Story story = currentStory.get();

Returns a null story, so maybe currentStory was never initialized

Unable to run jbehave .feature file with JUnitReportingRunner

Hi - I am using GherkinStoryParser using jbehave. When I use JUnitReportingRunner, only BeforeStories and AfterStories are run and the .feature file is not getting executed. Here is the code and error. Please help. What could be the issue? Any help is much appreciated.

@RunWith(JUnitReportingRunner.class)
public class CalcConfig extends JUnitStories {
public CalcConfig() {
super();
JUnitReportingRunner.recommandedControls(configuredEmbedder());
}
@OverRide
public Configuration configuration() {
Class<? extends Embeddable> embeddableClass = this.getClass();
return new MostUsefulConfiguration()
.useStoryParser(new GherkinStoryParser())
.useStoryLoader(new LoadFromClasspath(embeddableClass))
.useStoryReporterBuilder(
new StoryReporterBuilder().withDefaultFormats()
.withFormats(STATS, HTML, TXT, CONSOLE))
.useParameterControls(
new ParameterControls()
.useDelimiterNamedParameters(true));
}
@OverRide
public InjectableStepsFactory stepsFactory() {
return new InstanceStepsFactory(configuration(), new CalcSteps());
}
@OverRide
protected List storyPaths() {
return new StoryFinder().findPaths(
codeLocationFromClass(this.getClass()), "*/.feature", "");
}

}
============================ Here is the error I am getting:

Failed to run story test/resources/calculator/Calculator.feature java.lang.AbstractMethodError: de.codecentric.jbehave.junit.monitoring.JUnitScenarioReporter.lifecyle(Lorg/jbehave/core/model/Lifecycle;)V at org.jbehave.core.reporters.DelegatingStoryReporter.lifecyle(DelegatingStoryReporter.java:79) at org.jbehave.core.reporters.ConcurrentStoryReporter.lifecyle(ConcurrentStoryReporter.java:137) at org.jbehave.core.embedder.StoryRunner.runCancellable(StoryRunner.java:277) at org.jbehave.core.embedder.StoryRunner.run(StoryRunner.java:220) at org.jbehave.core.embedder.StoryRunner.run(StoryRunner.java:181) at org.jbehave.core.embedder.StoryManager$EnqueuedStory.call(StoryManager.java:229) at org.jbehave.core.embedder.StoryManager$EnqueuedStory.call(StoryManager.java:201) at java.util.concurrent.FutureTask$Sync.innerRun(FutureTask.java:303) at java.util.concurrent.FutureTask.run(FutureTask.java:138) at java.util.concurrent.ThreadPoolExecutor$Worker.runTask(ThreadPoolExecutor.java:895) at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:918) at java.lang.Thread.run(Thread.java:680)

(AfterStories)

Generating reports view to '/Documents/workspace/Calculator/jbehave' using formats '[stats, stats, html, txt, console, junitscenarioreporter]' and view properties '{defaultFormats=stats, decorateNonHtml=true, viewDirectory=view, decorated=ftl/jbehave-report-decorated.ftl, reports=ftl/jbehave-reports-with-totals.ftl, maps=ftl/jbehave-maps.ftl, navigator=ftl/jbehave-navigator.ftl, views=ftl/jbehave-views.ftl, nonDecorated=ftl/jbehave-report-non-decorated.ftl}' Reports view generated with 0 stories (of which 0 pending) containing 0 scenarios (of which 0 pending)

Gradle build fails "Could not write XML test results"

Hello, I have just started to use this project. On eclipse junit it works great. However when I try a Gradle build it fails because it can't write the xml test results.

I'm running on WIndows 7 64bits
Java version Java SE 1.6.0_45
Jbehave 3.8

The test case with all the information I think you need can be found at
https://github.com/jucoba/JavaWebTestUtils

Just run gradle build inside JavaWebTestUtilsProject

If you need any extra information please tell me

Thank you

org.gradle.api.tasks.TaskExecutionException: Execution failed for task ':CalculadoraApp:test'.
at org.gradle.api.internal.tasks.execution.ExecuteActionsTaskExecuter.executeActions(ExecuteActionsTaskExecuter.java:69)
at org.gradle.api.internal.tasks.execution.ExecuteActionsTaskExecuter.execute(ExecuteActionsTaskExecuter.java:46)
at org.gradle.api.internal.tasks.execution.PostExecutionAnalysisTaskExecuter.execute(PostExecutionAnalysisTaskExecuter.java:35)
at org.gradle.api.internal.changedetection.state.CacheLockReleasingTaskExecuter$1.run(CacheLockReleasingTaskExecuter.java:35)
at org.gradle.internal.Factories$1.create(Factories.java:22)
at org.gradle.cache.internal.DefaultCacheAccess.longRunningOperation(DefaultCacheAccess.java:179)
at org.gradle.cache.internal.DefaultCacheAccess.longRunningOperation(DefaultCacheAccess.java:232)
at org.gradle.cache.internal.DefaultPersistentDirectoryStore.longRunningOperation(DefaultPersistentDirectoryStore.java:142)
at org.gradle.api.internal.changedetection.state.DefaultTaskArtifactStateCacheAccess.longRunningOperation(DefaultTaskArtifactStateCacheAccess.java:83)
at org.gradle.api.internal.changedetection.state.CacheLockReleasingTaskExecuter.execute(CacheLockReleasingTaskExecuter.java:33)
at org.gradle.api.internal.tasks.execution.SkipUpToDateTaskExecuter.execute(SkipUpToDateTaskExecuter.java:58)
at org.gradle.api.internal.tasks.execution.ContextualisingTaskExecuter.execute(ContextualisingTaskExecuter.java:34)
at org.gradle.api.internal.changedetection.state.CacheLockAcquiringTaskExecuter$1.run(CacheLockAcquiringTaskExecuter.java:39)
at org.gradle.internal.Factories$1.create(Factories.java:22)
at org.gradle.cache.internal.DefaultCacheAccess.useCache(DefaultCacheAccess.java:124)
at org.gradle.cache.internal.DefaultCacheAccess.useCache(DefaultCacheAccess.java:112)
at org.gradle.cache.internal.DefaultPersistentDirectoryStore.useCache(DefaultPersistentDirectoryStore.java:134)
at org.gradle.api.internal.changedetection.state.DefaultTaskArtifactStateCacheAccess.useCache(DefaultTaskArtifactStateCacheAccess.java:79)
at org.gradle.api.internal.changedetection.state.CacheLockAcquiringTaskExecuter.execute(CacheLockAcquiringTaskExecuter.java:37)
at org.gradle.api.internal.tasks.execution.ValidatingTaskExecuter.execute(ValidatingTaskExecuter.java:57)
at org.gradle.api.internal.tasks.execution.SkipEmptySourceFilesTaskExecuter.execute(SkipEmptySourceFilesTaskExecuter.java:41)
at org.gradle.api.internal.tasks.execution.SkipTaskWithNoActionsExecuter.execute(SkipTaskWithNoActionsExecuter.java:51)
at org.gradle.api.internal.tasks.execution.SkipOnlyIfTaskExecuter.execute(SkipOnlyIfTaskExecuter.java:52)
at org.gradle.api.internal.tasks.execution.ExecuteAtMostOnceTaskExecuter.execute(ExecuteAtMostOnceTaskExecuter.java:42)
at org.gradle.api.internal.AbstractTask.executeWithoutThrowingTaskFailure(AbstractTask.java:282)
at org.gradle.execution.taskgraph.DefaultTaskPlanExecutor.executeTask(DefaultTaskPlanExecutor.java:48)
at org.gradle.execution.taskgraph.DefaultTaskPlanExecutor.processTask(DefaultTaskPlanExecutor.java:34)
at org.gradle.execution.taskgraph.DefaultTaskPlanExecutor.process(DefaultTaskPlanExecutor.java:27)
at org.gradle.execution.taskgraph.DefaultTaskGraphExecuter.execute(DefaultTaskGraphExecuter.java:89)
at org.gradle.execution.SelectedTaskExecutionAction.execute(SelectedTaskExecutionAction.java:29)
at org.gradle.execution.DefaultBuildExecuter.execute(DefaultBuildExecuter.java:61)
at org.gradle.execution.DefaultBuildExecuter.access$200(DefaultBuildExecuter.java:23)
at org.gradle.execution.DefaultBuildExecuter$2.proceed(DefaultBuildExecuter.java:67)
at org.gradle.api.internal.changedetection.state.TaskCacheLockHandlingBuildExecuter$1.run(TaskCacheLockHandlingBuildExecuter.java:31)
at org.gradle.internal.Factories$1.create(Factories.java:22)
at org.gradle.cache.internal.DefaultCacheAccess.useCache(DefaultCacheAccess.java:124)
at org.gradle.cache.internal.DefaultCacheAccess.useCache(DefaultCacheAccess.java:112)
at org.gradle.cache.internal.DefaultPersistentDirectoryStore.useCache(DefaultPersistentDirectoryStore.java:134)
at org.gradle.api.internal.changedetection.state.DefaultTaskArtifactStateCacheAccess.useCache(DefaultTaskArtifactStateCacheAccess.java:79)
at org.gradle.api.internal.changedetection.state.TaskCacheLockHandlingBuildExecuter.execute(TaskCacheLockHandlingBuildExecuter.java:29)
at org.gradle.execution.DefaultBuildExecuter.execute(DefaultBuildExecuter.java:61)
at org.gradle.execution.DefaultBuildExecuter.access$200(DefaultBuildExecuter.java:23)
at org.gradle.execution.DefaultBuildExecuter$2.proceed(DefaultBuildExecuter.java:67)
at org.gradle.execution.DryRunBuildExecutionAction.execute(DryRunBuildExecutionAction.java:32)
at org.gradle.execution.DefaultBuildExecuter.execute(DefaultBuildExecuter.java:61)
at org.gradle.execution.DefaultBuildExecuter.execute(DefaultBuildExecuter.java:54)
at org.gradle.initialization.DefaultGradleLauncher.doBuildStages(DefaultGradleLauncher.java:166)
at org.gradle.initialization.DefaultGradleLauncher.doBuild(DefaultGradleLauncher.java:113)
at org.gradle.initialization.DefaultGradleLauncher.run(DefaultGradleLauncher.java:81)
at org.gradle.launcher.exec.InProcessBuildActionExecuter$DefaultBuildController.run(InProcessBuildActionExecuter.java:64)
at org.gradle.launcher.cli.ExecuteBuildAction.run(ExecuteBuildAction.java:33)
at org.gradle.launcher.cli.ExecuteBuildAction.run(ExecuteBuildAction.java:24)
at org.gradle.launcher.exec.InProcessBuildActionExecuter.execute(InProcessBuildActionExecuter.java:35)
at org.gradle.launcher.exec.InProcessBuildActionExecuter.execute(InProcessBuildActionExecuter.java:26)
at org.gradle.launcher.cli.RunBuildAction.run(RunBuildAction.java:50)
at org.gradle.api.internal.Actions$RunnableActionAdapter.execute(Actions.java:171)
at org.gradle.launcher.cli.CommandLineActionFactory$ParseAndBuildAction.execute(CommandLineActionFactory.java:201)
at org.gradle.launcher.cli.CommandLineActionFactory$ParseAndBuildAction.execute(CommandLineActionFactory.java:174)
at org.gradle.launcher.cli.CommandLineActionFactory$WithLogging.execute(CommandLineActionFactory.java:170)
at org.gradle.launcher.cli.CommandLineActionFactory$WithLogging.execute(CommandLineActionFactory.java:139)
at org.gradle.launcher.cli.ExceptionReportingAction.execute(ExceptionReportingAction.java:33)
at org.gradle.launcher.cli.ExceptionReportingAction.execute(ExceptionReportingAction.java:22)
at org.gradle.launcher.Main.doAction(Main.java:48)
at org.gradle.launcher.bootstrap.EntryPoint.run(EntryPoint.java:45)
at org.gradle.launcher.Main.main(Main.java:39)
at org.gradle.launcher.bootstrap.ProcessBootstrap.runNoExit(ProcessBootstrap.java:50)
at org.gradle.launcher.bootstrap.ProcessBootstrap.run(ProcessBootstrap.java:32)
at org.gradle.launcher.GradleMain.main(GradleMain.java:26)
Caused by: org.gradle.api.GradleException: Could not write XML test results for Scenario: Ingreso a calculadora sin usuario to file D:\sura_desarrollo\JavaWeb
tils\JavaWebTestUtilsProject\CalculadoraApp\build\test-results\TEST-Scenario: Ingreso a calculadora sin usuario.xml.
at org.gradle.api.internal.tasks.testing.junit.result.Binary2JUnitXmlReportGenerator$1.execute(Binary2JUnitXmlReportGenerator.java:57)
at org.gradle.api.internal.tasks.testing.junit.result.Binary2JUnitXmlReportGenerator$1.execute(Binary2JUnitXmlReportGenerator.java:48)
at org.gradle.api.internal.tasks.testing.junit.result.TestReportDataCollector.visitClasses(TestReportDataCollector.java:95)
at org.gradle.api.internal.tasks.testing.junit.result.Binary2JUnitXmlReportGenerator.generate(Binary2JUnitXmlReportGenerator.java:48)
at org.gradle.api.tasks.testing.Test.executeTests(Test.java:455)
at org.gradle.api.internal.BeanDynamicObject$MetaClassAdapter.invokeMethod(BeanDynamicObject.java:216)
at org.gradle.api.internal.BeanDynamicObject.invokeMethod(BeanDynamicObject.java:122)
at org.gradle.api.internal.CompositeDynamicObject.invokeMethod(CompositeDynamicObject.java:147)
at org.gradle.api.tasks.testing.Test_Decorated.invokeMethod(Unknown Source)
at org.gradle.util.ReflectionUtil.invoke(ReflectionUtil.groovy:23)
at org.gradle.api.internal.project.taskfactory.AnnotationProcessingTaskFactory$StandardTaskAction.doExecute(AnnotationProcessingTaskFactory.java:217)
at org.gradle.api.internal.project.taskfactory.AnnotationProcessingTaskFactory$StandardTaskAction.execute(AnnotationProcessingTaskFactory.java:210)
at org.gradle.api.internal.project.taskfactory.AnnotationProcessingTaskFactory$StandardTaskAction.execute(AnnotationProcessingTaskFactory.java:199)
at org.gradle.api.internal.AbstractTask$TaskActionWrapper.execute(AbstractTask.java:526)
at org.gradle.api.internal.AbstractTask$TaskActionWrapper.execute(AbstractTask.java:509)
at org.gradle.api.internal.tasks.execution.ExecuteActionsTaskExecuter.executeAction(ExecuteActionsTaskExecuter.java:80)
at org.gradle.api.internal.tasks.execution.ExecuteActionsTaskExecuter.executeActions(ExecuteActionsTaskExecuter.java:61)
... 67 more
Caused by: java.lang.NullPointerException
at org.gradle.api.internal.xml.SimpleMarkupWriter.writeXmlAttributeEncoded(SimpleMarkupWriter.java:372)
at org.gradle.api.internal.xml.SimpleMarkupWriter.attribute(SimpleMarkupWriter.java:241)
at org.gradle.api.internal.tasks.testing.junit.result.JUnitXmlResultWriter.writeTests(JUnitXmlResultWriter.java:83)
at org.gradle.api.internal.tasks.testing.junit.result.JUnitXmlResultWriter.write(JUnitXmlResultWriter.java:60)
at org.gradle.api.internal.tasks.testing.junit.result.Binary2JUnitXmlReportGenerator$1.execute(Binary2JUnitXmlReportGenerator.java:54)
... 83 more

Use jbehave-junit-runner with Spring Test and JUnit4

Can I use jbehave-junit-runner with Spring Test? I use @RunWith annotation for Spring Test and I can't use it for JUnitReportingRunner. My code:

@ActiveProfiles("test-h2")
@RunWith(SpringJUnit4ClassRunner.class)
@ContextConfiguration(locations = {"classpath:applicationContext/test-applicationContext.xml"})
public abstract class AbstractConfigurationTest extends JUnitStories {

    @Override
    public Configuration configuration() {
        return new MostUsefulConfiguration().useStoryLoader(new LoadFromClasspath(this.getClass()))
                .useStoryReporterBuilder(new StoryReporterBuilder().withFormats(Format.CONSOLE).withFailureTrace(true));
    }
}

jbehave-junit-runner requires InjectableStepsFactory

This is just a small note for the troubleshooting section:

An older test was working just fine with the now deprecated JUnitStories.candidateSteps().

jbehave-junit-runner will not execute if this is being used. Instead, one should make sure JUnitStories.stepsFactory() is being used/overridden.

Great work!

Prepare maven build to generate release notes

We already have some kind of release notes, since we're documenting fixed issues via milestones. However, it makes sense to provide users with an overview of what has changed between releases.

Configure the maven-changes plugin to generate release notes.

Should support multithreaded story execution

Right now the reporting only works, when JBehave is executing the tests in a single thread. It'd be nice, to allow JBehave to run tests multithreaded - with working reporting to JUnit.

Implementation idea: put all state in the reporter (currentScenario, etc) in a ThreadLocal context. This should be achieved fairly easily and should work under the assumption that one scenario / story is completely executed in one Thread.

NullPointerException after install and configure it

HI there,

I tried to use your jbehave-junit-runner into my project but I got a java.lang.NullPointerException.

I just added it to my pom.xml and I included @RunWith(JUnitReportingRunner.class) in MyStories class, which extends to JUnitStories.

The failure trace is this one:
java.lang.NullPointerException
at de.codecentric.jbehave.junit.monitoring.JUnitReportingRunner.(JUnitReportingRunner.java:59)
at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:39)
at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:27)
at java.lang.reflect.Constructor.newInstance(Constructor.java:513)
at org.junit.internal.builders.AnnotatedBuilder.buildRunner(AnnotatedBuilder.java:31)
at org.junit.internal.builders.AnnotatedBuilder.runnerForClass(AnnotatedBuilder.java:24)
at org.junit.runners.model.RunnerBuilder.safeRunnerForClass(RunnerBuilder.java:57)
at org.junit.internal.builders.AllDefaultPossibilitiesBuilder.runnerForClass(AllDefaultPossibilitiesBuilder.java:29)
at org.junit.runners.model.RunnerBuilder.safeRunnerForClass(RunnerBuilder.java:57)
at org.junit.internal.requests.ClassRequest.getRunner(ClassRequest.java:24)
at org.junit.internal.requests.SortingRequest.getRunner(SortingRequest.java:21)
at org.eclipse.jdt.internal.junit4.runner.JUnit4TestReference.(JUnit4TestReference.java:33)
at org.eclipse.jdt.internal.junit4.runner.JUnit4TestClassReference.(JUnit4TestClassReference.java:25)
at org.eclipse.jdt.internal.junit4.runner.JUnit4TestLoader.createTest(JUnit4TestLoader.java:48)
at org.eclipse.jdt.internal.junit4.runner.JUnit4TestLoader.loadTests(JUnit4TestLoader.java:38)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:452)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:683)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.run(RemoteTestRunner.java:390)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.main(RemoteTestRunner.java:197)

If you need my code/class, let me know and I will send to you.

Thanks in advance

Spring @Transactional annotation was ignored by runners

Firstly, thank you for your very useful library! It helps me a lot for working with Spring, JBehave and JUnit.
I got an issue when I tried to use Spring @transactional annotation (to rollback transaction automatically): by using 'SpringJUnitReportingRunner', everything worked well but transaction didn't rollback. Then, I changed to use 'SpringJUnit4ClassRunner', run test again. After test done, I could saw transaction rollback as I expected, but very poor result in JUnit view :(. I was wonder if maybe Spring @transactional annotation was ignored by classes: SpringJUnitReportingRunner/ JUnitReportingRunner?

JUnitReportingRunner overwrites configured reporter

JUnitReportingRunner is overwritign all pre-configured reporters (for formats like XML, HTML and others).

Insted, JUnitReportingRunner could just add the JUnitScenarioReporter to the list of reporters configured by the existing StoryReporterBuilder, if any.

Not able to use GivenStories having Examples table in story files

To reproduce:

  • Have a story that uses GivenStories referring to a story that has an Examples table

Notice that the execution stops just after printing the example to be executed
By experimenting I also found out the following:

  • The execution succeeds if a story with not GivenStories is run before the one with GivenStories
  • Even when it executes correctly in the above scenario there is no check mark in the JUnit view for the steps in the story with the GivenStories

Here is the stack trace I see

17:47:11.406 [pool-2-thread-1] INFO  d.c.j.j.m.JUnitScenarioReporter - Example: {emailAddress=USER, password=PASSWORD, SecCodePageTitle=enterCode.title, OTP=TEMP.PASSCODE, HomePageTitle=home.title}
17:47:11.609 [main] INFO  d.c.j.j.m.JUnitScenarioReporter - Before Story: AfterStories 

(AfterStories)
17:47:11.609 [main] INFO  d.c.j.j.m.JUnitScenarioReporter - After Story: AfterStories(java.lang.Object) 

Generating reports view to 'C:\workspace_noSpace\maven.1337379448984\trunk\target\jbehave' using formats '[stats, selenium_context, console, html, junitscenarioreporter]' and view properties '{defaultFormats=stats, decorateNonHtml=true, viewDirectory=view, decorated=ftl/jbehave-report-decorated.ftl, reports=ftl/jbehave-reports-with-totals.ftl, maps=ftl/jbehave-maps.ftl, navigator=ftl/jbehave-navigator.ftl, views=ftl/jbehave-views.ftl, nonDecorated=ftl/jbehave-report-non-decorated.ftl}'
Reports view generated with 2 stories (of which 0 pending) containing 4 scenarios (of which 0 pending)
java.lang.RuntimeException: org.jbehave.core.embedder.Embedder$RunningStoriesFailed: Failures in running stories: 
vipmgr_switchOrg.story: org.jbehave.core.embedder.StoryManager$StoryExecutionFailed: vipmgr_switchOrg.story
    at de.codecentric.jbehave.junit.monitoring.JUnitReportingRunner.run(JUnitReportingRunner.java:116)
    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:467)
    at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:683)
    at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.run(RemoteTestRunner.java:390)
    at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.main(RemoteTestRunner.java:197)
Caused by: org.jbehave.core.embedder.Embedder$RunningStoriesFailed: Failures in running stories: 
vipmgr_switchOrg.story: org.jbehave.core.embedder.StoryManager$StoryExecutionFailed: vipmgr_switchOrg.story
    at org.jbehave.core.embedder.Embedder$ThrowingRunningStoriesFailed.handleFailures(Embedder.java:515)
    at org.jbehave.core.embedder.Embedder.handleFailures(Embedder.java:244)
    at org.jbehave.core.embedder.Embedder.runStoriesAsPaths(Embedder.java:226)
    at de.codecentric.jbehave.junit.monitoring.JUnitReportingRunner.run(JUnitReportingRunner.java:114)
    ... 6 more

AfterStories isn't finished any more

JUnit doesn't receive the notification any longer, that all tests are finished. When running, the notifications cause a higher testcount than originally estimated when creating the test desriptions.

Change whitespace policy from tabs to spaces

Although the tab character is the default indentation character in eclipse, it is not very well suited for distributed development. The display of the tab character depends on the clients OS and editor. For this reason it's common to use spaces for indentation. We should follow this commons practice.

Make use of Travis CI

Travis CI is a nice and easy way to get a project into a CI environment. Since it is for free, we should activate it for this project. This may require getting in touch with the owner of the codecentric github account. Docs on Travis CI can be found here.

And Steps don't show up

Scenario: using and steps

Given a variable x with value 3
And a variable x with value 3
When I multiply x by 3
And I multiply x by 5
Then x should equal 50

Both steps "And ..." don't show up in JUnit.

IntelliJ 13.0.2 Community Edition not showing scenario fails when step fails

I have a bunch of stories that I am trying to run using:

@RunWith(JUnitReportingRunner.class)
public class AllStories extends JUnitStories
{
...
}

In my pom.xml I have:

    <dependency>
        <groupId>de.codecentric</groupId>
        <artifactId>jbehave-junit-runner</artifactId>
        <version>1.1.0</version>
    </dependency>

The screenshot shows a step that has failed yet the scenario shows as passed. What could be causing this?
capture

NullPointerException when running stories without an initial description

Hi everyone,

I just wanted to let you know that I find something a bit odd (perhaps considerable as a bug?) when using jbehave-junit-runner 1.0.1.
If any story file doesn't contain an initial description before the first scenario definition, the test fails during initialization with the following stacktrace:

Processing system properties {}
Using controls EmbedderControls[batch=false,skip=false,generateViewAfterStories=true,ignoreFailureInStories=false,ignoreFailureInView=false,verboseFailures=false,verboseFiltering=false,storyTimeoutInSecs=300,threads=1]
Generating reports view to '/home/user/project/target/jbehave' using formats '[stats, console, txt, junitscenarioreporter]' and view properties '{defaultFormats=stats, decorateNonHtml=true, viewDirectory=view, decorated=ftl/jbehave-report-decorated.ftl, reports=ftl/jbehave-reports-with-totals.ftl, maps=ftl/jbehave-maps.ftl, navigator=ftl/jbehave-navigator.ftl, views=ftl/jbehave-views.ftl, nonDecorated=ftl/jbehave-report-non-decorated.ftl}'
Reports view generated with 2 stories (of which 0 pending) containing 16 scenarios (of which 0 pending)
java.lang.RuntimeException: java.lang.NullPointerException
at de.codecentric.jbehave.junit.monitoring.JUnitReportingRunner.run(JUnitReportingRunner.java:81)
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:467)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:683)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.run(RemoteTestRunner.java:390)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.main(RemoteTestRunner.java:197)
Caused by: java.lang.NullPointerException
at de.codecentric.jbehave.junit.monitoring.JUnitScenarioReporter.beforeStory(JUnitScenarioReporter.java:84)
at org.jbehave.core.reporters.DelegatingStoryReporter.beforeStory(DelegatingStoryReporter.java:67)
at org.jbehave.core.reporters.ConcurrentStoryReporter.beforeStory(ConcurrentStoryReporter.java:107)
at org.jbehave.core.embedder.StoryRunner.runBeforeOrAfterStories(StoryRunner.java:70)
at org.jbehave.core.embedder.StoryManager.runBeforeOrAfterStories(StoryManager.java:91)
at org.jbehave.core.embedder.StoryManager.runStories(StoryManager.java:75)
at org.jbehave.core.embedder.Embedder.runStoriesAsPaths(Embedder.java:202)
at de.codecentric.jbehave.junit.monitoring.JUnitReportingRunner.run(JUnitReportingRunner.java:79)
... 6 more

Looking up at JUnitScenarioReporter.java:84 I've found out that a description is necessary.
I would propose a fix myself but since I don't have currently the time to run through the whole code, I'm just signaling it :)

Btw, it looks like the problem doesn't appear if you are running a JUnitStory instead of JUnitStories, but I don't have time now to reproduce the thing.

Thanks!

JUnitReportingRunnerTest contains stubs

shouldGenerateDescriptionWithoutCrossReference() in JUnitReportingRunnerTest contains a TODO comment stating: "no idea how this should be tested!". This test method should either be fixed (preferred) or removed.

Jbehave error error reporting.

Version : 1.0.1
Problem:
When a step fails jbehave report seem to add '\u200B' at the end of the line in the error report, please see the example as below. Is it because of de.codecentric.jbehave.junit.monitoring.DescriptionTextUniquefier.getUniqueDescription.

com.test.steps.TrainingTest.When I perform a Java training\u200B
com.test.steps.TrainingTest.When I perform a Java training\u200B\u200B
com.test.steps.TrainingTest.When I perform a Java training\u200B\u200B\u200B
com.test.steps.TrainingTest.When I perform a Java training\u200B\u200B\u200B\u200B
com.test.steps.TrainingTest.When I perform a Java training\u200B\u200B\u200B\u200B\u200B
com.test.steps.TrainingTest.When I perform a Java training\u200B\u200B\u200B\u200B\u200B\u200B
com.test.steps.TrainingTest.When I perform a Java training\u200B\u200B\u200B\u200B\u200B\u200B\u200B
com.test.steps.TrainingTest.When I perform a Java training\u200B\u200B\u200B\u200B\u200B\u200B\u200B\u200B
com.test.steps.TrainingTest.When I perform a Java training\u200B\u200B\u200B\u200B\u200B\u200B\u200B\u200B\u200B

Can you please let me know if I am doing anything wrong?. I am using Single threaded tests.

Thanks
Girish

Progress not reported when step with tabular param commented out

When a step in a scenario looks like this

Given something with a few params:
| Header |
| Value  |

everthing works fine.

But when the step is commented out like this:

!-- Given something with a few params:
| Header |
| Value  |

JBehave executes the steps before and after that, however not progress is reported at all for any steps in any story in the IDE JUnit view.

Version: 1.0.2-SNAPSHOT as of 2012-05-31 17:45 ( commit 19c1b18 )

NPE when running "mvn clean test -Dtest=MyStories"

Hello,

I am using Netbeans which is delegating test runs to Maven/Surefire directly, so in the end it boils down to a call as mentioned in the title.

mvn clean test -Dtest=MyStories

Now I am getting:

-------------------------------------------------------------------------------
Test set: de.friedenhagen.jbehavesimple.MyStories
-------------------------------------------------------------------------------
Tests run: 1, Failures: 0, Errors: 1, Skipped: 0, Time elapsed: 0.338 sec <<< FAILURE!
de.friedenhagen.jbehavesimple.MyStories  Time elapsed: 0 sec  <<< ERROR!
java.lang.NullPointerException
    at de.codecentric.jbehave.junit.monitoring.JUnitScenarioReporter.<init>(JUnitScenarioReporter.java:55)
    at de.codecentric.jbehave.junit.monitoring.JUnitReportingRunner.run(JUnitReportingRunner.java:80)
    at org.apache.maven.surefire.junit4.JUnit4TestSet.execute(JUnit4TestSet.java:53)
    at org.apache.maven.surefire.junit4.JUnit4Provider.executeTestSet(JUnit4Provider.java:123)
    at org.apache.maven.surefire.junit4.JUnit4Provider.invoke(JUnit4Provider.java:104)
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
    at java.lang.reflect.Method.invoke(Method.java:597)
    at org.apache.maven.surefire.util.ReflectionUtils.invokeMethodWithArray(ReflectionUtils.java:164)
    at org.apache.maven.surefire.booter.ProviderFactory$ProviderProxy.invoke(ProviderFactory.java:110)
    at org.apache.maven.surefire.booter.SurefireStarter.invokeProvider(SurefireStarter.java:175)
    at org.apache.maven.surefire.booter.SurefireStarter.runSuitesInProcessWhenForked(SurefireStarter.java:107)
    at org.apache.maven.surefire.booter.ForkedBooter.main(ForkedBooter.java:68)

You may easily reproduce this by cloning git://github.com/mfriedenhagen/jbehave-simple.git and running mvn clean test -Dtest=MyStories.

Runner instantiate steps unnecessarily when building JUnit Descriptions

The JUnitReportingRunner instantiates step classes before any scenarios are actually executed as a part of an attempt to build JUnit Descriptions. This can create a problem with Guice integrations (and possibly others).

When Guice is configured to instantiate Step classes as singletons, it doesn't make any difference. But when using Guice custom scopes--for example, scoping a Step to a scenario--this causes the runner to fail, because objects required by the Step don't exist until a scenario exists. The exact error with stack trace is included below.

The problem code is inside JUnitDescriptionGenerator.addRegularStep(), as shown below:

    Description testDescription = Description.createTestDescription(step
            .getStepsInstance().getClass(), getJunitSafeString(stringStep));
    description.addChild(testDescription);

The Description requires the Class only, not an instance of the Class. Is there a way to obtain the Class of the Step without requiring an instance? That would fix this problem. A quick glance at the JBehave StepCandidate class suggest that the Class type is not exposed, but perhaps there is some other way to get it.

A link to a sample project exposing the problem is here: http://bit.ly/11pLRvq (sorry, it's the only way I could find to upload it--GitHub doesn't allow file attachments). Note: you must run it through Eclipse to see the problem. Maven does not see the test class. This problem is specific to the JUnitReportingRunner. Running with the default AnnotatedEmbedderRunner works normally.

Version information is in the pom.xml, and also included below:

jbehave-junit-runner: 1.0.1
jbehave: 3.6.9

Error:

com.google.inject.ProvisionException: Guice provision errors:

  1. Error in custom provider, com.google.inject.OutOfScopeException: Cannot access Key[type=example.ScenarioScopeSteps, annotation=[none]] outside of a scoping block
    at example.AppModule.configure(AppModule.java:12)
    while locating example.ScenarioScopeSteps

1 error
at com.google.inject.internal.InjectorImpl$4.get(InjectorImpl.java:987)
at com.google.inject.internal.InjectorImpl.getInstance(InjectorImpl.java:1009)
at org.jbehave.core.steps.guice.GuiceStepsFactory.addInstances(GuiceStepsFactory.java:72)
at org.jbehave.core.steps.guice.GuiceStepsFactory.createInstanceOfType(GuiceStepsFactory.java:61)
at org.jbehave.core.steps.StepCandidate.getStepsInstance(StepCandidate.java:68)
at de.codecentric.jbehave.junit.monitoring.JUnitDescriptionGenerator.addRegularStep(JUnitDescriptionGenerator.java:190)
at de.codecentric.jbehave.junit.monitoring.JUnitDescriptionGenerator.addExistingStep(JUnitDescriptionGenerator.java:148)
at de.codecentric.jbehave.junit.monitoring.JUnitDescriptionGenerator.addSteps(JUnitDescriptionGenerator.java:138)
at de.codecentric.jbehave.junit.monitoring.JUnitDescriptionGenerator.addStepsToExample(JUnitDescriptionGenerator.java:127)
at de.codecentric.jbehave.junit.monitoring.JUnitDescriptionGenerator.createDescriptionFrom(JUnitDescriptionGenerator.java:57)
at de.codecentric.jbehave.junit.monitoring.JUnitDescriptionGenerator.addAllScenariosToDescription(JUnitDescriptionGenerator.java:208)
at de.codecentric.jbehave.junit.monitoring.JUnitDescriptionGenerator.createDescriptionFrom(JUnitDescriptionGenerator.java:44)
at de.codecentric.jbehave.junit.monitoring.JUnitReportingRunner.addStories(JUnitReportingRunner.java:194)
at de.codecentric.jbehave.junit.monitoring.JUnitReportingRunner.buildDescriptionFromStories(JUnitReportingRunner.java:181)
at de.codecentric.jbehave.junit.monitoring.JUnitReportingRunner.(JUnitReportingRunner.java:51)
at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:39)
at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:27)
at java.lang.reflect.Constructor.newInstance(Constructor.java:513)
at org.junit.internal.builders.AnnotatedBuilder.buildRunner(AnnotatedBuilder.java:31)
at org.junit.internal.builders.AnnotatedBuilder.runnerForClass(AnnotatedBuilder.java:24)
at org.junit.runners.model.RunnerBuilder.safeRunnerForClass(RunnerBuilder.java:57)
at org.junit.internal.builders.AllDefaultPossibilitiesBuilder.runnerForClass(AllDefaultPossibilitiesBuilder.java:29)
at org.junit.runners.model.RunnerBuilder.safeRunnerForClass(RunnerBuilder.java:57)
at org.junit.internal.requests.ClassRequest.getRunner(ClassRequest.java:24)
at org.eclipse.jdt.internal.junit4.runner.JUnit4TestReference.(JUnit4TestReference.java:33)
at org.eclipse.jdt.internal.junit4.runner.JUnit4TestClassReference.(JUnit4TestClassReference.java:25)
at org.eclipse.jdt.internal.junit4.runner.JUnit4TestLoader.createTest(JUnit4TestLoader.java:48)
at org.eclipse.jdt.internal.junit4.runner.JUnit4TestLoader.loadTests(JUnit4TestLoader.java:38)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:452)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:683)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.run(RemoteTestRunner.java:390)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.main(RemoteTestRunner.java:197)
Caused by: com.google.inject.OutOfScopeException: Cannot access Key[type=example.ScenarioScopeSteps, annotation=[none]] outside of a scoping block
at example.SimpleScope.getScopedObjectMap(SimpleScope.java:97)
at example.SimpleScope.access$0(SimpleScope.java:94)
at example.SimpleScope$2.get(SimpleScope.java:81)
at com.google.inject.internal.InternalFactoryToProviderAdapter.get(InternalFactoryToProviderAdapter.java:40)
at com.google.inject.internal.InjectorImpl$4$1.call(InjectorImpl.java:978)
at com.google.inject.internal.InjectorImpl.callInContext(InjectorImpl.java:1024)
at com.google.inject.internal.InjectorImpl$4.get(InjectorImpl.java:974)
... 32 more

Move example stories into separate example project

Currently we have several example stories in the src/test folder. While mvn test will ignore these tests and give you immediate feedback if everything is okay, running all tests in eclipse/intellij will show a red bar. This is because some of the example stories are only there to fail. This is confusing and we should create a new example project that only contains the example stories. The src/test folder in the main project should only contain real tests for the library.

After/Before Story/Scenario not listed

“After/Before Stories” is always listed although not present, but for Story or Scenario they are not listed, even when present.

I guess this stems from the problem not to know which steps class has (or hasn’t) such methods and which one of them failed.

Missing steps are not reported, related scenarios are OK

If a new scenario is added with missing steps (no binding code exists), the steps are not added to the report tree and even worse, the scenario is marked OK.

Personally I’d want those to be reported as failures (with a stub implementation text extractable from the failure trace) – but I can imagine others might not want this behaviour; Is there a possibility to add configuration options to the JUnitReportingRunner?

The missing steps should at least be reported like pending steps.

Should delegate to configured storyReporter

Currently, when setting up the JUnitReportingRunner, the configured storyReporter is discarded. Instead the own JUnitScenarioReporter is used in order to receive notifications from JBehave.

This probably also causes #8.

When executing the provided example with maven-surefire-plugin no test is executed

I have this pom.xml:

            <plugin>
                <artifactId>maven-surefire-plugin</artifactId>
                <executions>
                    <execution>
                        <id>default-test</id>
                        <configuration>
                            <skipTests>true</skipTests>
                        </configuration>
                    </execution>
                    <execution>
                        <id>integration-test</id>
                        <phase>integration-test</phase>
                        <goals>
                            <goal>test</goal>
                        </goals>
                        <configuration>
                            <redirectTestOutputToFile>false</redirectTestOutputToFile>
                            <failIfNoTests>true</failIfNoTests>
                            <includes>
                                <include>**/tests/**/Math*Tests.java</include>
                            </includes>
                        </configuration>
                    </execution>
                </executions>
            </plugin>

When executing it's telling me:
[INFO] --- maven-surefire-plugin:2.10:test (integration-test) @ functional.tests ---
[INFO] Surefire report directory: D:\repos\git\ops\functional-tests\target\surefire-reports

-------------------------------------------------------
 T E S T S
-------------------------------------------------------
Running com.onassignment.ops.tests.MathStoriesTests
Tests run: 0, Failures: 0, Errors: 0, Skipped: 0, Time elapsed: 0.485 sec

Results :

Tests run: 0, Failures: 0, Errors: 0, Skipped: 0

I was expecting some number, and a nice JUnit compatible report.

Test count is wrong in combination with missing steps

In relation to #5, the count of run/found tests is wrong when a story contains missing steps:

When a scenario contains only missing steps, nothing is counted to the total, but an additional run is counted.

Given a story with only one scenario consisting of missing steps
When the story is run in JUnit
Then 3/2 runs are reported

Considering missing steps are to be reported:

Then 5/5 runs should be reported

(The 2 extra runs are for the Before/After Stories steps)

This might be a side-effect of an empty tree entry for test descriptions, automatically solved when #5 is solved.

Please release a version to support latest stable JBehave core release 3.9

Hi
We really benefit from using your jar to provide us with clearer debugs and runs through eclipse. However we have just upgraded from JBehave-core-3.8 to 3.9 (released mid dec 2013) and found that we cannot use version 1.0.2 with this.

Please could you update jbehave-junit-runner to support jbehave-core-3.9 and junit-4.11?

many thanks

FailingUponPendingStep strategy causes a RuntimeException

Configuring JBehave to fail on pending steps causes a RuntimeException in 1.0.1.

@RunWith(JUnitReportingRunner.class)
public class Foobar extends JUnitStory {
    @Override
    public Configuration configuration() {
        return super.configuration().usePendingStepStrategy(new FailingUponPendingStep());
    }
}
java.lang.RuntimeException: org.jbehave.core.embedder.Embedder$RunningStoriesFailed: Failures in running stories: 
foo/foobar.story: org.jbehave.core.embedder.StoryManager$StoryExecutionFailed: foo/foobar.story
    at de.codecentric.jbehave.junit.monitoring.JUnitReportingRunner.run(JUnitReportingRunner.java:81)
    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:467)
    at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:683)
    at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.run(RemoteTestRunner.java:390)
    at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.main(RemoteTestRunner.java:197)
Caused by: org.jbehave.core.embedder.Embedder$RunningStoriesFailed: Failures in running stories: 
foo/foobar.story: org.jbehave.core.embedder.StoryManager$StoryExecutionFailed: foo/foobar.story
    at org.jbehave.core.embedder.Embedder$ThrowingRunningStoriesFailed.handleFailures(Embedder.java:495)
    at org.jbehave.core.embedder.Embedder.handleFailures(Embedder.java:224)
    at org.jbehave.core.embedder.Embedder.runStoriesAsPaths(Embedder.java:205)
    at de.codecentric.jbehave.junit.monitoring.JUnitReportingRunner.run(JUnitReportingRunner.java:79)
    ... 6 more

Logging dependencies might interfere with projects under test

In my current project there is an older slf4j-API version in use. Although backwards compatible, it is a hassle to reconfigure builds and settings to use the newer API just to satisfy the JUnit runner. As there usually is no need for any users of the runner to see its internal logging output, I recommend an (even simpler ;-)) approach to logging for internal use.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.