serenity-bdd / serenity-cucumber

Cucumber integration for the Serenity BDD Reporting library
Other
78 stars 74 forks source link

NPE when empty .feature file present #149

Closed daczczcz1 closed 6 years ago

daczczcz1 commented 6 years ago

Summary

When an empty .feature file is present in the 'features' path specified in the runner there is a NPE thrown.

Expected Behavior

Even if a NullPointerException is to be thrown, there should be some information about the cause of it (e.g. name of empty file). IMHO a it could be a warning log.

Current Behavior This is the stack trace:

java.lang.NullPointerException
at cucumber.runtime.formatter.TestSourcesModel.parseGherkinSource(TestSourcesModel.java:161)
at cucumber.runtime.formatter.TestSourcesModel.getFeature(TestSourcesModel.java:87)
at cucumber.runtime.formatter.SerenityReporter.featureFrom(SerenityReporter.java:180)
at cucumber.runtime.formatter.SerenityReporter.handleTestSourceRead(SerenityReporter.java:150)
at cucumber.runtime.formatter.SerenityReporter.lambda$new$0(SerenityReporter.java:111)
at cucumber.runner.EventBus.send(EventBus.java:28)
at cucumber.runtime.model.CucumberFeature.sendTestSourceRead(CucumberFeature.java:132)
at cucumber.runtime.RuntimeOptions.cucumberFeatures(RuntimeOptions.java:315)
at cucumber.api.junit.Cucumber.(Cucumber.java:80)
at net.serenitybdd.cucumber.CucumberWithSerenity.(CucumberWithSerenity.java:38)
at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:62)
at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45)
at java.lang.reflect.Constructor.newInstance(Constructor.java:423)
at org.junit.internal.builders.AnnotatedBuilder.buildRunner(AnnotatedBuilder.java:104)
at org.junit.internal.builders.AnnotatedBuilder.runnerForClass(AnnotatedBuilder.java:86)
at org.junit.runners.model.RunnerBuilder.safeRunnerForClass(RunnerBuilder.java:59)
at org.junit.internal.builders.AllDefaultPossibilitiesBuilder.runnerForClass(AllDefaultPossibilitiesBuilder.java:26)
at org.junit.runners.model.RunnerBuilder.safeRunnerForClass(RunnerBuilder.java:59)
at org.junit.internal.requests.ClassRequest.getRunner(ClassRequest.java:33)
at com.intellij.junit4.JUnit4IdeaTestRunner.startRunnerWithArgs(JUnit4IdeaTestRunner.java:49)
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)

Possible Solution

As stated before: a warning when an empty .feature file is found

Steps to Reproduce (for bugs)

  1. Runner:

    @RunWith(CucumberWithSerenity.class)
    @CucumberOptions(
    
        glue = {
                "*****.cucumberHook",
                "*****.citrus.steps",
                "*****.selenium.steps",
                "com.consol.citrus.cucumber.step.runner.core"
        },
        features = {
                "classpath:features",
        },
        format = {
                "json:target/cucumber-report/cucumber.json",
                "pretty",
                "html:target/site/cucumber-pretty",
                "json:target/cucumber.json"
        },
        junit = "--step-notifications",
        monochrome = true,
        tags = {
       "@New",
        }
      )
  2. Add an empty .feature file

    1. Start test (in my case through IntelliJ Idea)

Context & Motivation

I found the problem cause straight away, since I was working on some new test cases. However, if these would have been changes introduced by another user in a big team, the time spent troubleshooting could be significantly longer.

I first addressed this issue to the Cucumber project. They found out that this is a problem with Serenity-BDD. They provided a project that helped find out the cause: https://github.com/mlvandijk/npeissue

Version used: 1.1.6
Operating System and version: Windows 10 Enterptise
wakaleo commented 6 years ago

The null pointer exception is thrown in the TestSourcesModel class, which is part of the Cucumber code base, not the Serenity code base. It happens when the Serenity runner is used, because the Serenity reporter parses the feature file, but the bug is definitely inside the Cucumber code - the Cucumber parser throws a null pointer rather than raising a syntax error if no feature name is found.

Serenity now catches this exception and reports that the feature file was ignored.

daczczcz1 commented 6 years ago

Thank you for a very fast response! I'll forward your observation to the Cucumber team.