Mockito中的@SpyBean和@MockBean有什么区别? [英] What is difference between @SpyBean and @MockBean in Mockito?

查看:825
本文介绍了Mockito中的@SpyBean和@MockBean有什么区别?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

Mockito中的@SpyBean@MockBean批注之间有什么区别?

What is the difference between the @SpyBean and @MockBean annotations in Mockito?

我已经看过JavaDoc,但没有发现不同.如有可能,请举例说明何时使用 MockBean SpyBean .

I have already gone through the JavaDoc but didn't get the difference. If possible please give an example when to use MockBean and when SpyBean.

推荐答案

模拟(无论我们谈论的是普通对象还是bean)都只是一个空的外壳".

A mock (no matter if we talk about ordinary objects or beans) is simply an "empty shell".

该模拟对象与基础生产代码没有 any 关系.这是一个看起来像 的对象,成为类X的对象.但是,在该可笑事物上,X确实没有真正"执行过任何方法或字段.

That mock object doesn't have any relation to the underlying production code. It is an object that looks like being an object of class X. But none of the methods or fields that X has do "really" exist on that mocked thing.

而间谍包装围绕被测类的现有对象.含义:创建间谍程序时,可以决定是否应拦截"对间谍程序的方法调用(然后使用间谍程序,就好像它是模拟程序一样);或传递"到间谍包裹的实际对象.

Whereas a spy wraps around an existing object of your class under test. Meaning: when you create a spy, you can decide if method calls going to the spy should be "intercepted" (then you are using the spy as if it would be a mock); or be "passed through" to the actual object the spy wraps around.

请参见此处一些特定于Bean的示例.或者 ...

See here for some bean specific examples. Or there ...

这篇关于Mockito中的@SpyBean和@MockBean有什么区别?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆