@Target(value=TYPE) @Retention(value=RUNTIME) @Documented @Inherited @Import(value=MockedBeanRegistrar.class) public @interface EnableMockedBean
MockedBean annotations
will be properly processed.
@ComponentScan()
@EnableMockedBean
@EnableAutoConfiguration
@RunWith(SpringJUnit4ClassRunner.class)
@SpringApplicationConfiguration(classes = MySampleServiceTest.class)
public class MySampleServiceTest {
@Autowired
@MockedBean
private HelloWorldService helloWorldService;
@Test
public void helloWorldIsCalledOnlyOnce() throws Exception {
// WHEN I launch SampleSimpleApplication
SampleSimpleApplication.main(new String[0]);
// THEN HelloWorldService is called only once
verify(helloWorldService,times(1)).getHelloMessage();
}
}
Copyright © 2015. All rights reserved.