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 on Failure.getTestHeader(Failure.java:44) when step throws assert in Lifecycle>After>FAILURE #159

Open
MosheElisha opened this issue Dec 6, 2018 · 0 comments

Comments

@MosheElisha
Copy link

MosheElisha commented Dec 6, 2018

Hi,

When a step inside Lifecycle>After>FAILURE throws an assertion, you get a NPE:

Caused by: java.lang.NullPointerException
  at org.junit.runner.notification.Failure.getTestHeader(Failure.java:44)
...
  at com.github.valfirst.jbehave.junit.monitoring.JUnitScenarioReporter.failed(JUnitScenarioReporter.java:273)
...

Full stack trace here: mvn_NPE.txt

I saw that the cause of the null is here - https://github.com/valfirst/jbehave-junit-runner/blob/master/src/main/java/com/github/valfirst/jbehave/junit/monitoring/JUnitScenarioReporter.java#L273

The expression testState.currentStep evaluates to null and passed further.

You can reproduce with these files:

Steps file:

package com;

import org.jbehave.core.annotations.Then;
import org.junit.Assert;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

public class TestSteps {
    @Then("I assert with message $assertMessage")
    public void assertWithMessage(String assertMessage) {
        Assert.fail(assertMessage);
    }
}

Story file:

Lifecycle:
After:
Outcome: FAILURE
Then I assert with message AfterAssert1

Scenario: Test lifecycle
Then I assert with message ScenarioAssert1

The NPE does not occur if the step in the After>FAILURE does not throw an assert.
Similarly, the NPE does not occur if I use Outcome=ANY instead of FAILURE

Relevant mvn dependency:

[INFO] +- net.serenity-bdd:serenity-core:jar:2.0.20:compile
[INFO] +- net.serenity-bdd:serenity-junit:jar:2.0.20:compile
[INFO] +- net.serenity-bdd:serenity-jbehave:jar:1.44.0:compile
[INFO] |  +- com.thoughtworks.paranamer:paranamer:jar:2.8:compile
[INFO] |  +- org.jbehave:jbehave-core:jar:4.3.5:compile
[INFO] |  |  +- org.hamcrest:hamcrest-integration:jar:1.3:compile
[INFO] |  |  \- org.codehaus.plexus:plexus-utils:jar:3.1.0:compile
[INFO] |  +- com.github.valfirst:jbehave-junit-runner:jar:2.2.0:compile
[INFO] |  +- org.reflections:reflections:jar:0.9.11:compile
[INFO] |  |  \- org.javassist:javassist:jar:3.21.0-GA:compile
[INFO] |  \- org.codehaus.groovy:groovy-all:jar:2.4.13:compile

Thanks.

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

No branches or pull requests

1 participant