Overriding Binding in Guice

前端 未结 5 839
我在风中等你
我在风中等你 2020-11-28 03:37

I\'ve just started playing with Guice, and a use-case I can think of is that in a test I just want to override a single binding. I think I\'d like to use the rest of the pr

5条回答
  •  庸人自扰
    2020-11-28 04:01

    You want to use Juckito where you can declare your custom configuration for each test class.

    @RunWith(JukitoRunner.class)
    class LogicTest {
        public static class Module extends JukitoModule {
    
            @Override
            protected void configureTest() {
                bind(InterfaceC.class).to(MockC.class);
            }
        }
    
        @Inject
        private InterfaceC logic;
    
        @Test
        public testLogicUsingMock() {
            logic.foo();
        }
    }
    

提交回复
热议问题