-
-
Notifications
You must be signed in to change notification settings - Fork 2k
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
Aspectj annotation is being ignored while using Spring and Cucumber v7.10.0 onwords #2886
Comments
Interesting. Haven't quite got the time to dig into a bug project like this, but could you put |
I have tried that, but then I end up getting the well known error messsage:
I was a bit hasty yesterday when creating the issue. I have added here a more detailed steps to reproduce it:
So if you are able to open this project in your IDEA, Eclipse or Visual Studio Code. Add a breakpoint here: LogExecutionTimeAspect.java I created this project to help others to understand ssl/tls. So it is a tutorial having spring boot as a server and the client module has over 40+ http clients as example to give others also code examples with actual working tests. And I use cucumber in the client module to test all of them. It contains a mixture of Java, Kotlin and Scala code which the project can build. It has worked so far, but I am not able to understand why bumping cucumber makes the AspectJ pointcut fail. So the workaround for me is to remove the following line in the feature file: Hello.feature#L9 and remove AspectJ and not logging execution time. So that won't be a big deal actually, but I am just curious what is causing in version I hope this detailed description is a bit more helpful compared to my initial issue description |
That is informative! Could you try annotating the |
Thank you! That worked like a charm. Amazing that you found the issue that quickly! I did the adjustment here: Hakky54/mutual-tls-ssl@f8bb438 and the build is passing, see here: https://github.com/Hakky54/mutual-tls-ssl/actions/runs/9206458636 We can close this issue. Thank you for your help! It seems like I wrongly configured cucumber and spring. But is cucumber more strict in the configuration setup from version 7.10.0 onwords? It seems that my existing setup was not an issue in the past, but maybe not the correct way to setup everything.... |
Oh, it was just a guess. But you're welcome! I'll leave this open for now, ideally Cucumber would catch misconfiguration with a clear exception message. But I don't really understand why what you did here would be wrong - and that doesn't make for a good explanation / instruction. |
Cucumber uses Spring Test Context Manager framework. This framework was written for JUnit and assumes that there is a "test instance". Cucumber however uses multiple step definition classes and so it has multiple test instances. Originally `@CucumberContextConfiguration` was added to signal to Spring which class should be used to configure the application context from. But as people also expected mock beans and other features provided by Springs test execution listeners to work (#2661) the annotated instance was only instantiated but never initialized by Spring. This changed the semantics somewhat as now features that depend on the bean being initialized stopped working (#2886). Unfortunately, there is little that can be done here. Spring expects that the instance provided to the Test Context Manager to be an uninitialized bean. The solution for this is to put the context configuration and step definitions in different classes. Cleaning up the examples to follow this pattern should avoid this problem somewhat in the future. Though I won't go as far as recommending people do this. Putting everything in one class looks quite nice. And generally still works. Closes: #2886
Cucumber uses Spring Test Context Manager framework. This framework was written for JUnit and assumes that there is a "test instance". Cucumber however uses multiple step definition classes and so it has multiple test instances. Originally `@CucumberContextConfiguration` was added to signal to Spring which class should be used to configure the application context from. But as people also expected mock beans and other features provided by Springs test execution listeners to work (#2661) the annotated instance was only instantiated but never initialized by Spring. This changed the semantics somewhat as now features that depend on the bean being initialized stopped working (#2886). Unfortunately, there is little that can be done here. Spring expects that the instance provided to the Test Context Manager to be an uninitialized bean. The solution for this is to put the context configuration and step definitions in different classes. Cleaning up the examples to follow this pattern should avoid this problem somewhat in the future. Though I won't go as far as recommending people do this. Putting everything in one class looks quite nice. And generally still works. Closes: #2886
Okay. As it turns out, nothing is wrong here. Prior to #2661 cucumber instantiated and initialized the annotated classes. However Spring expected only an instantiated raw bean. As we stopped instantiating, things like AspectJ also stopped working. |
Ah, it makes sense now and the additional documentation for this topic in your PR is also helpful. Thank you for further investigating this |
Cucumber uses Spring Test Context Manager framework. This framework was written for JUnit and assumes that there is a "test instance". Cucumber however uses multiple step definition classes and so it has multiple test instances. Originally `@CucumberContextConfiguration` was added to signal to Spring which class should be used to configure the application context from. But as people also expected mock beans and other features provided by Springs test execution listeners to work (#2661) the annotated instance was only instantiated but never initialized by Spring. This changed the semantics somewhat as now features that depend on the bean being initialized stopped working (#2886). Unfortunately, there is little that can be done here. Spring expects that the instance provided to the Test Context Manager to be an uninitialized bean. The solution for this is to put the context configuration and step definitions in different classes. Cleaning up the examples to follow this pattern should avoid this problem somewhat in the future. Though I won't go as far as recommending people do this. Putting everything in one class looks quite nice. And generally still works. Closes: #2886
👓 What did you see?
I am using Cucumber alongside with Spring ans Aspectj. This setup always worked. I was on version
7.2.3
of cucumber. I tried bumping it to 7.18.0 however some part of my tests failed. It was not picking up the aspectj annotations of the before and after step. I am not qure what is causing the issue. However If I downgrade to version 7.9.0 it still works. If I bump it to 7.10.0 it fails.✅ What did you expect to see?
I would expect my existing test suite still be working
📦 Which tool/library version are you using?
JDK 17
Maven
🔬 How could we reproduce it?
mvn clean verify
it will throw nullpointer exceptionThe before and after call in LogExecutionTimeAspect.java is being ignored somehow while it is still working on version 7.9.0
📚 Any additional context?
No response
The text was updated successfully, but these errors were encountered: