有没有人遇到过@MockkBean
似乎没有实际工作或至少存根没有通过的问题?
简单的例子:
@RunWith(SpringRunner::class)
@WebMvcTest(controllers = [WidgetController::class])
class WidgetTest {
@Autowired
private lateinit var mockMvc: MockMvc
@MockkBean
private lateinit var widgetService: WidgetService
@Test
fun test() {
val value = objectMapper.readValue<MyWidget>(something()))
every {
widgetService.getWidget(ArgumentMatchers.anyString())
} returns value
mockMvc
.perform(
get(
"/apis/widget/v1/widget"
).contentType(MediaType.APPLICATION_JSON)
)
.andExpect {
JSONAssert.assertEquals(
widgetPayload(),
it.response.contentAsString,
false
)
}
}
}
结果是:
org.springframework.web.util.NestedServletException: Request processing failed; nested exception is io.mockk.MockKException: no answer found for: WidgetService(com.bondhouse.pms.services.externalportfolios.ExternalPortfoliosService#0 bean#1).getWidget(test)