-
Notifications
You must be signed in to change notification settings - Fork 28
Description
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.