Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support injecting methods of testing services #5

Open
nlativy opened this issue Mar 21, 2015 · 0 comments
Open

Support injecting methods of testing services #5

nlativy opened this issue Mar 21, 2015 · 0 comments

Comments

@nlativy
Copy link
Collaborator

nlativy commented Mar 21, 2015

Currently each TestingService is instantiated once per environment. This means if you wish to do something with an object bound with a @TestScoped binding you need to use a Provider.

A common example might be a service that quits the webdriver instance started for an individual test:

class WebDriverQuitter implements TestingService {
  @Inject Provider<WebDriver> webDriver;

  @AfterTest void quitWebDriver() throws Exception {
    // Calling get on the Provider here returns the instance
    // for the test case which we are currently tearing down.
    webDriver.get().quit();
  }
}

If we supported injecting each @BeforeTest, @AfterTest method then this could become:

class WebDriverQuitter implements TestingService {
  @AfterTest void quitWebDriver(Webdriver webDriver) throws Exception {
    webDriver.quit();
  }
}

injecting the correct instance for the current test scope.

While cute this adds a bit of complexity so we should consider if it's worth bloating the API for something that's already achievable anyway. Also the scope will not be test scope when running @BeforeSuite methods so we should be careful that doesn't cause confusion.

Also would users then want to inject test methods too? That doesn't add as much value since the scope is the same as when injecting the test object. It would mean objects used in one test case only could be injected there rather than being fields but in such cases maybe the user should be splitting into multiple test classes anyway. Worth considering if this inconsistency between test methods and test services would be confusing though if we only supported injecting the service methods.

@nlativy nlativy changed the title Consider support injecting methods in testing services Consider supporting injecting methods of testing services Mar 21, 2015
@nlativy nlativy changed the title Consider supporting injecting methods of testing services Support injecting methods of testing services Mar 21, 2015
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

1 participant