I recently added an @After hook to a class that contained my StepDefinitions.
However, this @After hook was also called by all other scenarios1, which was not my intention.
As a matter of fact, that @After I added was executing similar code as an @After in another StepDefinition class. I verified that both @After annotated methods were executed for each and every scenario, and they were.
So I decided to move all @After annotated methods into a "GlobalStepDefinition" class, and collaps all of them into one method.
Incidentally, reference [3] shows why we should not have many of these end-to-end tests.
References
- [1] GitHub Issues - Before and After methods invoked for unused step definition classes #1005
- https://github.com/cucumber/cucumber-jvm/issues/1005
- [2] Cucumber - Polymorphic Step Definitions
- https://cucumber.io/blog/2015/07/08/polymorphic-step-definitions
- [3] MartinFowler.com - TestPyramid
- https://martinfowler.com/bliki/TestPyramid.html
No comments:
Post a Comment