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 while running empty scenario via AbstractTestNGCucumberTests #1885

Closed
fslev opened this issue Feb 4, 2020 · 2 comments · Fixed by #1887
Closed

NPE while running empty scenario via AbstractTestNGCucumberTests #1885

fslev opened this issue Feb 4, 2020 · 2 comments · Fixed by #1887
Labels
🐛 bug Defect / Bug
Milestone

Comments

@fslev
Copy link

fslev commented Feb 4, 2020

Steps to reproduce:

  1. Create empty scenario
Feature: Feature with empty scenario

  Scenario: Empty scenario

2.) Create a TestNG class for running feature from above:

@RunWith(Cucumber.class)
@CucumberOptions(features = "src/test/resources/features/EmptyScenario.feature",
        glue = {"com.cucumber.utils"}, plugin = {"pretty", "junit:target/junit/cucumber-reports.xml",
        "json:target/cucumber-report/report.json", "timeline:target/cucumber-report/timeline"},
        tags = {"not @Ignore", "not @ignore"})
public class CucumberUtilsTest extends AbstractTestNGCucumberTests implements ITest {

    private ThreadLocal<String> testName = new ThreadLocal<>();

    @Override
    @DataProvider(parallel = true)
    public Object[][] scenarios() {
        return super.scenarios();
    }

    @BeforeMethod
    public void BeforeMethod(Method method, Object[] testData, ITestContext ctx) {
        if (testData.length > 0) {
            testName.set(testData[0].toString());
            ctx.setAttribute("testName", testName.get());
        } else
            ctx.setAttribute("testName", method.getName());
    }

    @Override
    public String getTestName() {
        return testName.get();
    }
}
  1. Run test

Actual:

java.lang.NullPointerException
	at io.cucumber.testng.TestCaseResultListener.createUndefinedException(TestCaseResultListener.java:116)
	at io.cucumber.testng.TestCaseResultListener.getError(TestCaseResultListener.java:86)
	at io.cucumber.testng.TestNGCucumberRunner.runScenario(TestNGCucumberRunner.java:126)
	at io.cucumber.testng.AbstractTestNGCucumberTests.runScenario(AbstractTestNGCucumberTests.java:29)
	at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
	at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
	at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
	at java.base/java.lang.reflect.Method.invoke(Method.java:566)
	at org.testng.internal.MethodInvocationHelper.invokeMethod(MethodInvocationHelper.java:134)
	at org.testng.internal.TestInvoker.invokeMethod(TestInvoker.java:597)
	at org.testng.internal.TestInvoker.invokeTestMethod(TestInvoker.java:173)
	at org.testng.internal.TestMethodWithDataProviderMethodWorker.call(TestMethodWithDataProviderMethodWorker.java:77)
	at org.testng.internal.TestMethodWithDataProviderMethodWorker.call(TestMethodWithDataProviderMethodWorker.java:15)
	at java.base/java.util.concurrent.FutureTask.run(FutureTask.java:264)
	at java.base/java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:515)
	at java.base/java.util.concurrent.FutureTask.run(FutureTask.java:264)
	at java.base/java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1128)
	at java.base/java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:628)
	at java.base/java.lang.Thread.run(Thread.java:834)

@fslev fslev added the 🐛 bug Defect / Bug label Feb 4, 2020
@fslev
Copy link
Author

fslev commented Feb 4, 2020

Running via JUnit, it seems no error is thrown:

Scenario: Empty scenario # src/test/resources/features/EmptyScenario.feature:3
[INFO] Tests run: 1, Failures: 0, Errors: 0, Skipped: 0, Time elapsed: 0.584 s - in Feature with empty scenario

@mpkorstanje
Copy link
Contributor

The empty scenario somewhat unexpectedly gets the state "Undefined". This unexpected because by definition an empty test should pass. As a result however the TestCaseResultListener probably expects there to be a skipped step.

Now I'm guessing the TestCaseState defaults to Undefined when there are no step results because the result is literally undefined, but that is not the meaning of undefined state.

So ideally we fix that and default to passed. But that will need a major release so the next best thing would be to fix the listeners.

mpkorstanje added a commit that referenced this issue Feb 4, 2020
The `TestCaseState` defaults to undefined when a scenario has no steps. The
`TestCaseResultListener` however expects there to be an undefined step.

That the `TestCaseState` defaults to undefined is rather unexpected. The status
should be the most severe of the states so far which means that it should
default to passed. Changing this however will require a major release.

So fixing the test case result listeners is the next best thing. It also
appears that there is some duplication ongoing between TestNG and the JUnit
Platform Engine. However this duplication is hard to fix because each
platform uses its own exceptions and TestNG still supports `--non-strict`.

Fixes: #1885
@mpkorstanje mpkorstanje added this to the 5.x.x milestone Feb 4, 2020
mpkorstanje added a commit that referenced this issue Feb 5, 2020
The `TestCaseState` defaults to undefined when a scenario has no steps. The
`TestCaseResultListener` however expects there to be an undefined step.

That the `TestCaseState` defaults to undefined is rather unexpected. The status
should be the most severe of the states so far which means that it should
default to passed. Changing this however will require a major release.

So fixing the test case result listeners is the next best thing. It also
appears that there is some duplication ongoing between TestNG and the JUnit
Platform Engine. However this duplication is hard to fix because each
platform uses its own exceptions and TestNG still supports `--non-strict`.

Fixes: #1885
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
🐛 bug Defect / Bug
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants