我的测试设置如下:
@RunWith(SpringJUnit4ClassRunner.class)
@ContextConfiguration(classes = TestConfig.class)
public class ExampleServiceTest {
@Resource(name = "exampleService")
@InjectMocks
private ExampleService ExampleService;
@Mock
private ServiceB serviceB;
@Before
public void setUp() {
MockitoAnnotations.initMocks(this);
}
}
ExampleService已经使用@RefreshScope进行了注释,因为添加了该注释,当测试运行时,ServiceB的实际实现将在ExampleService中注入。