Dependency Injection

Dependency injection (DI) is a technique that allows us to isolate a class from its concrete dependencies until runtime.[34] Often this is used to defer the decision about which actual implementation of an interface we’re going to use. On this occasion, however, Cucumber uses a dependency injection framework to create a single instance of a class and share that instance between all the step definition classes that need to use it. (We’ll talk about Cucumber’s use of DI much more in Chapter 11, Simplifying Design with Dependency Injection .)

Cucumber ships with integrations to several popular DI frameworks to choose from. We’ll use PicoContainer[35] which is probably the most lightweight and is also available under the ...

Get The Cucumber for Java Book now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.