Mockito:使用@RefreshScope注释spring bean后不会注入Mocked实例

时间:2017-01-09 13:56:42

标签: java spring spring-cloud

我的测试设置如下:

@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中注入。

0 个答案:

没有答案