My Cucumber Java step definitions can create AutoCloseable
objects, which can acquire external (perhaps scarce) resources. Those objects should have their close()
method called when they are no longer needed, to free those resources. How do I ensure that the close()
methods are called?
In a non-Cucumber test, I'd use try-with-resources. But that is not possible because there is no single method that spans the execution of a scenario (an AutoCloseable
object might be created in a when method, and used in a later then).