当然
null,由于
@InjectMocks您正在创建一个新实例,因此依赖关系将在Spring的可见范围之外,因此不会自动进行连线。
Spring Boot提供了广泛的测试支持,并且可以用模拟代替bean,请参阅Spring
Boot参考指南的“测试”部分。
要对其进行修复,请使用框架而不是围绕框架。
- 替换
@Mock
为@MockBean
- 替换
@InjectMocks
为@Autowired
- 删除设置方法
同样显然,您只需要为SOAP存根提供一个模拟(因此不确定对于
LottoClientfor来说需要模拟什么)。
这样的事情应该可以解决问题。
@SpringBootTestpublic class LottoClientServiceImplTest { @MockBean SoapServiceBindingStub soapServiceBindingStub; @Autowired LottoClientServiceImpl lottoClientService; @Test public void getLastResults() throws Exception { RespLastWyniki expected = Fake.generateFakeLastWynikiResponse(); when(soapServiceBindingStub.getLastWyniki(anyString())).thenReturn(expected); LastResults actual = lottoClientService.getLastResults();


