Skip to content
This repository has been archived by the owner on May 21, 2019. It is now read-only.
aslakhellesoy edited this page Sep 13, 2010 · 6 revisions

If you are using Google Guice in your application, you can get your dependencies injected into your step definitions with the GuiceFactory. Enabling Guice is done with a jvm argument:

-Dcuke4duke.objectFactory=cuke4duke.internal.jvmclass.GuiceFactory

You also have to provide the class name of the Guice configuration module you wish to use. This is also a jvm argument:

-Dcuke4duke.guiceModule=billing.DependenciesModule

All test steps are now injected with Guice. This means that you can use @Inject exactly as you use it in your application.

public class BillingSteps {

    @Inject
    private BillingService billingService;

    private Transaction transaction;

    private CreateTransactionResponse response;

    @Given("^I have a transaction$")
    public void iHaveATransaction() {
        transaction = new Transaction("12345678", new BigDecimal("50.00"));
    }

    @When("^I send the transaction to billing$")
    public void iSendTheTransactionToBilling() {
        response = billingService.sendTransactionToBilling(transaction);
    }

    @Then("^the response should be OK$")
    public void theResponseShouldBeOK() {
        assertTrue(response.isOK());
    }

}

Check out the Guice example for a complete example.

Clone this wiki locally