prashant-ramcharan / courgette-jvm

Multiprocess | Parallel Cucumber-JVM | Parallelize your Java Cucumber tests on a feature level or on a scenario level.
MIT License
134 stars 39 forks source link

NullPointerException when features specified using "classpath" in cucumberOptions #418

Closed ykartsev closed 1 month ago

ykartsev commented 1 month ago

Having this:

@RunWith(CourgetteRunner.class)
@CourgetteOptions(
        threads = 1,
        runLevel = CourgetteRunLevel.FEATURE,
        testOutput = CourgetteTestOutput.CONSOLE,
        cucumberOptions = @CucumberOptions(
              features = {"classpath:features"},
              glue = { "com/mine/automation/stepdef", "com/mine/automation/hook" },
              tags = {"@smoke"},
              plugin = {"pretty",
                      "json:build/courgette-report/courgette.json"}
        ))
public class LocalTestRunner
{
}

And features situated under src/test/resources/features, execution causes the following exception:

java.lang.NullPointerException: Cannot invoke "String.split(String)" because the return value of "java.net.URI.getPath()" is null
        at courgette.runtime.CourgetteReportOptions.getFeatureId(CourgetteReportOptions.java:54)
        at courgette.runtime.CourgetteReportOptions.createFeatureIdWithLine(CourgetteReportOptions.java:60)
        at courgette.runtime.CourgetteReportOptions.<init>(CourgetteReportOptions.java:19)
        at courgette.runtime.CourgetteRunnerInfo.<init>(CourgetteRunnerInfo.java:30)
        at courgette.api.junit.Courgette.lambda$new$0(Courgette.java:39)
        at java.base/java.util.ArrayList.forEach(ArrayList.java:1596)
        at courgette.api.junit.Courgette.<init>(Courgette.java:39)
...

Offending method is below:

    public String getFeatureId() {
        return Arrays.stream(feature.getUri().getPath().split("/")).reduce((x, y) -> y)
                .orElse("").replace(".feature", "")
                .toLowerCase();
    }

The reason behind is that feature.getUri().getPath() returns null in case of using classpath:features as value for features. Debugging shows that the value of getUri() is classpath:features/MyFeature.feature

Java version is 21, courgette-jvm version is 6.16.0. Thank you.

prashant-ramcharan commented 1 month ago

Thanks, I will put a fix for this.

prashant-ramcharan commented 1 month ago

This is now released in version 6.17.0

ykartsev commented 1 month ago

I can confirm 6.17.0 fixed the issue. Thank you for a quick turnaround!