Improving Our Design Using DI

As we’ve seen, DI can make our lives simpler by doing some of our work for us. At the moment our application is using DI to share some state, but code in KnowsTheDomain is managing the creation of quite a few domain entities. As our application grows, we’re likely to find more domain entities that need to be shared between our step definitions. The temptation would be to put all our shared domain entities into KnowsTheDomain, but this would soon grow huge, exhibiting the Monster Object antipattern.[54]

To keep our step definitions maintainable, it’s a good idea to create a step definition class for each domain entity. It’s clear that the Cash Slot step definition is going to need to interact with the Cash Slot ...

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.