google / google/acai

Support injecting methods of testing services

Open
#5 0 comments 0 reactions 0 assignees View on GitHub
enhancement
Dominant language
Java
Stars
82
Forks
30
PR merge metrics
No merged PRs in 30d

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:

``` Java
class WebDriverQuitter implements TestingService {
@Inject Provider 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:

``` Java
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.

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.