cucumber/cucumber-jvm — pull request #571 by sirchia (2013-08-18 19:30:04+00:00)
Title: Spring test support for @DirtiesContext and non-Spring step defs

Hi,

First of all, good to see the migration towards the Spring TestContextManager. Spring based tests now feel a lot more 'natural' in 1.1.4.

In our tests, we desire a completely clean system for each scenario. Normal Spring based tests like this use the @DirtiesContext annotation on classes and/or methods and the DirtiesContextTestExecutionListener is triggered by the TestContextManager to refresh the context when such a test class/method is done.

While the scenario's can't be mapped on test methods, the @DirtiesContext annotation can at least be supported on a class level by calling before-/afterTestClass on the TestContextManager whenever that step-def instance is requested for the 1st time from the SpringFactory and when the stop() method is called. This also opens the door for usage of any other TestExecutionListeners. The reason this is done on 1st getInstance instead of that class and not on start() is to prevent eager initialisation of steps contexts that may even remain unused for that scenario.

Additionally, this pull request allows for non-spring dependent step classes to be initialised by the SpringFactory without causing TestContextManager initialisation to fail on them, making it tolerant for non-spring context defining step definitions.

Finally, some tests are added/extended to verify the new functionality.

Kind regards,

Riccardo Sirchia