serenity-bdd / serenity-cucumber

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

@After hook not executed after failed test case #194

Closed akihirogh closed 5 years ago

akihirogh commented 5 years ago

I have a number of tests for rest endpoints of service using MySql database. I implement @After hook that make a request to clear all the test data created during tests. When I run some test from cucumber .feature file and it's fails, hook will be executed and that's ok. But in case of running from class with annotation @RunWith(CucumberWithSerenity.class) hook is not executed at all (Despite the @After annotation).

Dependency I'm using: serenity-cucumber version: 1.9.15 serenity-core version: '1.9.30'

Debug shows, that in method invoke() from cucumber-jvm/../cucumber/runtime/Utils.java method cannot access to Hook method for clear request (but the method access is public)

The same is in net.thucydides.core.steps.StepInterceptor:

" can not access a member of class java.lang.reflect.Method with modifiers "private" "

in this context method is getMetaClass() called from test @Steps class.

P.s. I've checked some other versions and combination of 1.9.45 for core and 1.9.10 executes Hook.

wakaleo commented 5 years ago

Could you display the full stack trace?

akihirogh commented 5 years ago

java.lang.NullPointerException: Cannot invoke method code() on null objectat org.codehaus.groovy.runtime.NullObject.invokeMethod(NullObject.java:91)at org.codehaus.groovy.runtime.callsite.PogoMetaClassSite.call(PogoMetaClassSite.java:47)at org.codehaus.groovy.runtime.callsite.CallSiteArray.defaultCall(CallSiteArray.java:47)at org.codehaus.groovy.runtime.callsite.NullCallSite.call(NullCallSite.java:34)at org.codehaus.groovy.runtime.callsite.CallSiteArray.defaultCall(CallSiteArray.java:47)at org.codehaus.groovy.runtime.callsite.AbstractCallSite.call(AbstractCallSite.java:116)at org.codehaus.groovy.runtime.callsite.AbstractCallSite.call(AbstractCallSite.java:120)at...Hook.groovy:24)at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)at java.lang.reflect.Method.invoke(Method.java:498)at cucumber.runtime.Utils$1.call(Utils.java:31)at cucumber.runtime.Timeout.timeout(Timeout.java:16)at cucumber.runtime.Utils.invoke(Utils.java:25)at cucumber.runtime.java.JavaHookDefinition.execute(JavaHookDefinition.java:60)at cucumber.runtime.HookDefinitionMatch.runStep(HookDefinitionMatch.java:17)at cucumber.runner.UnskipableStep.executeStep(UnskipableStep.java:22)at cucumber.api.TestStep.run(TestStep.java:83)at cucumber.api.TestCase.run(TestCase.java:58)at cucumber.runner.Runner.runPickle(Runner.java:80)at cucumber.runtime.junit.PickleRunners$NoStepDescriptions.run(PickleRunners.java:140)at cucumber.runtime.junit.FeatureRunner.runChild(FeatureRunner.java:68)at cucumber.runtime.junit.FeatureRunner.runChild(FeatureRunner.java:23)at org.junit.runners.ParentRunner$3.run(ParentRunner.java:290)at org.junit.runners.ParentRunner$1.schedule(ParentRunner.java:71)at org.junit.runners.ParentRunner.runChildren(ParentRunner.java:288)at org.junit.runners.ParentRunner.access$000(ParentRunner.java:58)at org.junit.runners.ParentRunner$2.evaluate(ParentRunner.java:268)at org.junit.runners.ParentRunner.run(ParentRunner.java:363)at cucumber.runtime.junit.FeatureRunner.run(FeatureRunner.java:73)at cucumber.api.junit.Cucumber.runChild(Cucumber.java:118)at cucumber.api.junit.Cucumber.runChild(Cucumber.java:56)at org.junit.runners.ParentRunner$3.run(ParentRunner.java:290)at org.junit.runners.ParentRunner$1.schedule(ParentRunner.java:71)at org.junit.runners.ParentRunner.runChildren(ParentRunner.java:288)at org.junit.runners.ParentRunner.access$000(ParentRunner.java:58)at org.junit.runners.ParentRunner$2.evaluate(ParentRunner.java:268)at cucumber.api.junit.Cucumber$1.evaluate(Cucumber.java:127)

wakaleo commented 5 years ago

This looks like a Groovy library version conflict (there is no Serenity code in the stack trace)

akihirogh commented 5 years ago

I've tried many, but only one combination I've found executing hook after failing test is below

net.serenity-bdd:serenity-gradle-plugin:1.9.45 org.codehaus.groovy:groovy-all:2.4.5' serenityCoreVersion = '1.9.45' serenityCucumberVersion = '1.9.10'

wakaleo commented 5 years ago

Those are quite old versions - have you tried with more recent ones?

akihirogh commented 5 years ago

Yes, I've tried some newest versions For this "serenityCucumberVersion = '1.9.10" lower versions not working as well as higher

wakaleo commented 5 years ago

The @After hook is executed correctly for both passing and failing tests in serenity-core 2.0.30 and serenity-Cucumber 1.9.22. If you are still having the problems described, it is a version conflict unrelated to Serenity, so you will need to do a dependency analysis on your project.

akihirogh commented 5 years ago

It seems that these versions are working without issues. Thanks for help !

wakaleo commented 5 years ago

👍