Dependency Injection has become an integral part of modern software design. We discuss here the different ways in which JBehave supports dependency injection.
JBehave supports the following depency inejction containers:
When using Guice we can specify the inject from separate modules for configuration and steps.
When using PicoContainer we can specify the container from separate modules for configuration and steps.
When using Spring, we can specify the context from separate locations for configuration and steps.
Steps classes often use external dependencies to interface to the system whose behaviour is being verified.
CandidateSteps can be created with Guice using the GuiceStepsFactory:
where the GuiceTraderSteps is appropriately Guice-annotated:
public class GuiceTraderSteps extends TraderSteps { @Inject public GuiceTraderSteps(TradingService service) { super(service); } }
CandidateSteps can be created with PicoContainer using the PicoStepsFactory:
CandidateSteps can be created with Spring using the SpringStepsFactory: