Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Closed
jopombar opened this issue May 15, 2012 · 11 comments
Labels
Milestone

Comments

@jopombar
Copy link

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

@AndreasEK
Copy link
Contributor

Hi,

I assume that with fixing Issue #9 I also fixed this one. Since I am not using the Selenium Web and also no CrossReferences yet, I found it hard to reproduce the NPE. Please download the latest 1.0.0-SNAPSHOT or get it as maven dependency from https://oss.sonatype.org/content/repositories/snapshots/de/codecentric/jbehave-junit-runner/1.0.0-SNAPSHOT. Thanks!

@AndreasEK
Copy link
Contributor

Hi,

could you please let me know, if your bug is fixed? You can get the final 1.0.0 release of the library frrom maven central.

Andreas

@jopombar
Copy link
Author

Hello,
I tried both by getting the jar from here: https://oss.sonatype.org/content/repositories/snapshots/de/codecentric/jbehave-junit-runner/1.0.0-SNAPSHOT/
And adding this dependency on my pom.xml:

de.codecentric
jbehave-junit-runner
1.0.0

In both instances I get the same error reported above:

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.findMatchingStep(JUnitDescriptionGenerator.java:145)
    at de.codecentric.jbehave.junit.monitoring.JUnitDescriptionGenerator.addSteps(JUnitDescriptionGenerator.java:110)
    at de.codecentric.jbehave.junit.monitoring.JUnitDescriptionGenerator.addScenarioSteps(JUnitDescriptionGenerator.java:103)
    at de.codecentric.jbehave.junit.monitoring.JUnitDescriptionGenerator.createDescriptionFrom(JUnitDescriptionGenerator.java:63)
    at de.codecentric.jbehave.junit.monitoring.JUnitDescriptionGenerator.createDescriptionFrom(JUnitDescriptionGenerator.java:47)
    at de.codecentric.jbehave.junit.monitoring.JUnitReportingRunner.buildDescriptionFromStories(JUnitReportingRunner.java:108)
    at de.codecentric.jbehave.junit.monitoring.JUnitReportingRunner.<init>(JUnitReportingRunner.java:61)
    at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
    at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:57)
    at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45)
    at java.lang.reflect.Constructor.newInstance(Constructor.java:525)
    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)

@AndreasEK
Copy link
Contributor

Hm, ok, I will try to reproduce this. If this is not too much work, could you provide a sample without Selenium? Just to keep it simple :)

@AndreasEK
Copy link
Contributor

Hi,

I could reproduce the error. Fixing it is a different question, but it should not be impossible ... I hope :) The "problem" is that while generating the test descriptions for JUnit, the step monitor tries to report that it found a matching step, which then notifies also the CrossReference, which is not completely setup at that point. Also, I wonder if the cross-reference should be notified at all, in this stage. We'll see :)

Andreas

@AndreasEK
Copy link
Contributor

Hi,

could you please check if the latest 1.0.1-SNAPSHOT fixes this issue? There's still some cleaning up todo in the code, but I hope it's working now.

Andreas

@jopombar
Copy link
Author

Hi Andreas,
Thanks again for the very quick turn around. I did take the newest snapshot but I still see a similar stack trace (different lines for the jbehave-junit-runner classes). Please let me know how I can help. Here it is

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.findMatchingStep(JUnitDescriptionGenerator.java:145)
    at de.codecentric.jbehave.junit.monitoring.JUnitDescriptionGenerator.addSteps(JUnitDescriptionGenerator.java:110)
    at de.codecentric.jbehave.junit.monitoring.JUnitDescriptionGenerator.addScenarioSteps(JUnitDescriptionGenerator.java:103)
    at de.codecentric.jbehave.junit.monitoring.JUnitDescriptionGenerator.insertDescriptionForExamples(JUnitDescriptionGenerator.java:97)
    at de.codecentric.jbehave.junit.monitoring.JUnitDescriptionGenerator.createDescriptionFrom(JUnitDescriptionGenerator.java:61)
    at de.codecentric.jbehave.junit.monitoring.JUnitDescriptionGenerator.createDescriptionFrom(JUnitDescriptionGenerator.java:47)
    at de.codecentric.jbehave.junit.monitoring.JUnitReportingRunner.buildDescriptionFromStories(JUnitReportingRunner.java:108)
    at de.codecentric.jbehave.junit.monitoring.JUnitReportingRunner.<init>(JUnitReportingRunner.java:61)
    at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
    at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:57)
    at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45)
    at java.lang.reflect.Constructor.newInstance(Constructor.java:525)
    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)

@AndreasEK
Copy link
Contributor

Hi,

the line numbers in the stack trace don't match the latest version, that I commited. Can you please check which SNAPSHOT-version you got?

The latest Snapshot (jbehave-junit-runner-1.0.1-20120522.180232-8.jar) is either available from this repository:

https://oss.sonatype.org/content/repositories/snapshots/de/codecentric/jbehave-junit-runner/

Or from the downloads https://github.com/codecentric/jbehave-junit-runner/downloads

I just doublechecked that in both places the latest version is available. Thanks!

Andreas

@jopombar
Copy link
Author

You are completely right, I picked up the 5/18 instead of the 5/22 version. The latest did fix this issue. I did run into some a different problem when using "GivenStories". I'll open a new issue for it. Thanks a lot for the help you guys rock!

@AndreasEK
Copy link
Contributor

Thank you! That makes me smile -> :)

Also good, that this issue is fixed. Because if it weren't, I had no idea, what to do next ;)

@jopombar
Copy link
Author

Makes me smile too :)
Just for completness and in case it helps anyone, I did have to add this dependency to make it work

    <!-- slf4j-api is automatically included by logback-classic with runtime scope
         I think this dependency below will be required if we start using slf4j logging in our code
    <dependency>
      <groupId>org.slf4j</groupId>
      <artifactId>slf4j-api</artifactId>
      <version>1.6.4</version>
    </dependency>
    -->
    <dependency>
      <groupId>ch.qos.logback</groupId>
      <artifactId>logback-classic</artifactId>
      <scope>runtime</scope>
      <version>1.0.3</version>
    </dependency>

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants