We don’t allow questions seeking recommendations for software libraries, tutorials, tools, books, or other off-site resources. You can edit the question so it can be answered with facts and citations.
Closed 2 years ago.
The community reviewed whether to reopen this question last year and left it closed:
Original close reason(s) were not resolved
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
接受
或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
发布评论
评论(3)
我建议使用 Mockito Framework,它非常易于使用和理解。
如果你想使用属于entityManager的任何方法,你应该调用。
当您运行测试时,之前在 Mockito.when 中为 EntityManager 声明的任何调用都将返回声明中放入的值。
请在此处阅读完整文档。
https://static.javadoc .io/org.mockito/mockito-core/2.12.0/org/mockito/Mockito.html#stubbing
I suggest to use Mockito Framework it is very easy to use and understand.
If you want to use any method that belongs to entityManager, you should call.
When you run your test, any call previosly declared in the Mockito.when for the EntityManager will return the value put in the declaration..
Read full documentation here.
https://static.javadoc.io/org.mockito/mockito-core/2.12.0/org/mockito/Mockito.html#stubbing
对于模拟,我建议使用 powermock。多亏了自动生成的代理,它几乎可以做你能想象到的任何事情,从从接口创建模拟开始,通过拦截初始化,最后抑制静态初始化(唯一让我困惑的是模拟
java.lang.Object< /代码>)。
假设
SessionFacadeTest
是SeesionFacade
的 JUnit 测试套件。(注意:我在这里写的,所以可能无法编译,但会给你一个想法)。
For mocking, I'd suggest powermock. Thanks to auto generated proxies, it can do virtually anything you can imagine, starting with creating mocks from interfaces, through intercepting initialization finishing with suppressing static initialization (the only thing that beat me was messing with mocking
java.lang.Object
).Let's say the
SessionFacadeTest
is your JUnit test suite forSeesionFacade
.(Note: I wrote it here, so may even not compile, but shall give you the idea).
我通常使用 EasyMock 来模拟测试用例中的具体服务实现。查看他们的用户指南。它包括一个非常容易遵循的分步指南,它解释了一般模拟框架背后的基本概念,并让您快速启动并运行 EasyMock。
I'm usually using EasyMock for mocking concrete service implementation in test cases. Check out their user guide. It includes a a very easy to follow step-by-step guide, which explains the basic concepts behind mocking frameworks in general and gets you up and running with EasyMock fast.