How do I define dynamic and just

I am trying to use Guice for a test framework based on TestNG. This frameworks analyzes the test class for dependencies and provides them eliminating the need to build them in tests.

Guice is all about injection and I think is a good fit for the framework. But the question is how do I define bindings after I have created the injector? This is needed because tests may override bindings to substitute default implementations with mocks.

Besides that, I want to guess the implementation at runtime in some cases based on class names conventions. Sounds like Just-in-type binding feature. But how do I provide my own just-in-time binding provider?


That kind of dynamic behaviour isn't supported out-of-the-box, but you can achieve a lot with module rewriting. Take a look at Guiceberry, which already implements mock-substitution for JUnit tests. (And consider submitting a TestNG patch to them, they'd love that!)

链接地址: http://www.djcxy.com/p/94642.html

上一篇: 吉斯专家的问题

下一篇: 我如何定义动态和公正?