开发者

AtUnit and guice module overrides

I would like to use

Module functionalTestModule
    = Modules.override(new ProductionModule()).with(new TestModule());

for test cases so I can inherit all the production bindings and just override them for tests(开发者_开发技巧replacing instances with mocks). Is there a way to do this with AtUnit. The implementing Module seems weird in the design since I would think we would want to just inherit all production bindings and mock the ones needed, but maybe there is a second way of doing other than having the test implement Module.

Maybe there is a way to annotate AtUnit telling AtUnit the production module in the test case and then having configure in the test case that gets the TestModule overrides? is there such a way?

thanks, Dean


I don't really know anything about AtUnit, but a quick look at it makes it look like you just implement Module in your test. I don't know if there's some other way of doing it, but following those rules you could just do:

public class SomeTest implements Module {
  public void configure(Binder binder) {
    binder.install(Modules.override(new ProductionModule()).with(new TestModule()));
  }
}
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜