How to define dynamic and precisely snapped bindings to Guice?

I am trying to use Guice for TestNG based test environment. This structure analyzes the test class for dependencies and ensures their elimination of the need to create them in tests.

Guice is all about injections, and I think it works well for the framework. But the question is, how to determine the bindings after I created the injector? This is necessary because tests can override bindings to replace default implementations with mocks.

Also, I want to guess the runtime implementation in some cases based on class naming conventions. Sounds like a one-in-one binding function. But how can I provide my own time reference provider?

+3
source share
1 answer

This dynamic behavior is not supported out of the box, but you can achieve a lot by rewriting the module. Check out Guiceberry , which is already implementing a mockup replacement for JUnit tests. (And consider giving them the TestNG patch, they will like it!)

+3
source

Source: https://habr.com/ru/post/1716284/


All Articles