Search code examples
cucumber-java

After feature hook in cucumber feature files


Is there a specific reason for cucumber to not to support after_feature hook like Background. We have several use cases where it would have been ideal if we had this feature.

e.g. Suppose multiple scenarios in a feature file does db updates. At the end of each scenario those db updates should be reverted back. Whenever there's a failure in a scenario, reverting part cannot be done. This can cause failures in subsequent scenarios

Now we are using step definition level After hooks to revert scenario tag level changes. But we prefer if this can be done in feature file itself since step definitions are parameterized.

Other option is to prevent using hard asserts in step definitions so that it is guaranteed entire scenario is executed.


Solution

  • Despite Background addresses test set-up phase it operates with business steps in order to concentrate on specific business steps of a scenario.

    It is not the same as Before hook. The latter addresses technical aspect of test preparation (as well as After hook).

    Since business users normally do not care of database clean up or any technical stuff underneath the business layer, it does not make sense to expose such level of control on feature file level.