sbabcoc / JUnit-Foundation

JUnit Foundation is a lightweight collection of JUnit watchers, interfaces, and static utility classes that supplement and augment the functionality provided by the JUnit API.
Apache License 2.0
22 stars 6 forks source link

Classcast exception in case tests are executed via Cucumber junit runner #50

Closed avarabyeu closed 5 years ago

avarabyeu commented 5 years ago

In case tests are being executed with non-standard junit runner, the following class cast exception occurs:

java.lang.ClassCastException: class cucumber.runtime.junit.PickleRunners$NoStepDescriptions cannot be cast to class org.junit.runners.model.FrameworkMethod (cucumber.runtime.junit.PickleRunners$NoStepDescriptions and org.junit.runners.model.FrameworkMethod are in unnamed module of loader 'app')

    at com.nordstrom.automation.junit.AtomicTest.<init>(AtomicTest.java:38)
    at com.nordstrom.automation.junit.RunAnnouncer.newAtomicTest(RunAnnouncer.java:95)
    at com.nordstrom.automation.junit.RunAnnouncer.testStarted(RunAnnouncer.java:27)

Since org.junit.runners.ParentRunner does not explicitly specify object type of children, junit-found seems to be also should not rely on FrameworkMethod only. For example, for Cucumber JUnit runner children have cucumber.runtime.junit.PickleRunners$NoStepDescriptions type

avarabyeu commented 5 years ago

The problem has been fixed a bit in the latest version. After update i have the following:

java.lang.NullPointerException
    at com.epam.reportportal.junit.ReportPortalListener.testStarted(ReportPortalListener.java:73)
    at com.nordstrom.automation.junit.RunAnnouncer.testStarted(RunAnnouncer.java:36)
    at org.junit.runner.notification.SynchronizedRunListener.testStarted(SynchronizedRunListener.java:49)
    at org.junit.runner.notification.RunNotifier$3.notifyListener(RunNotifier.java:121)
    at org.junit.runner.notification.RunNotifier$SafeNotifier.run(RunNotifier.java:72)
    at org.junit.runner.notification.RunNotifier.fireTestStarted(RunNotifier.java:118)

Which basically means that junit calls testStarted method on watch providing NULL atomicTest. For example: com.nordstrom.automation.junit.RunAnnouncer#testStarted

I would suggest that we add NULL validation in RunAnnouncer before calling any method on testWatcher.

sbabcoc commented 5 years ago

I do not use Cucumber. Consequently, I have no way to reproduce this issue. However, the only way this could happen is if the Cucumber runner is using private internal JUnit entry points directly, which is unsupported behavior. The AtomicTest is required. This is what provides the context, identity, and status for the test. I could detect this bad behavior more gracefully, but the end result would be the same... No AtomicTest, no reporting.

sbabcoc commented 5 years ago

I stand corrected... I looked over the Cucumber runner, and it's done correctly. I just hadn't supported the ParentRunner generic implementation properly. I have a set of changes in the works that I think will handle this stuff the way it should.