JMockit 休眠仿真
我想知道是否有人尝试过使用 JMockit Hibernate Emulation?
Jmockit 文档表示,当运行 Hibernate Emulation 测试时,它们不会使用 O/R 映射信息。 因此,这意味着它不会测试 O/R 映射、HQL 查询字符串、本机查询等。那么 Hibernate Emulation 的真正好处是什么? 人们可以创建 MyDAO 模拟并使用它进行测试。 为什么要费心去模拟 hibenrate 呢?只需模拟所有 DAO 即可。 你怎么认为 ?
谢谢。
I was wondering if anyone tried using JMockit Hibernate Emulation?
Jmockit documentation says that when Hibernate Emulation tests are run, they won't use the O/R mapping information. So, this means it doesn't test O/R mappings, HQL query strings, Native queries, etc. Then what really are the benefits of Hibernate Emulation? One can just create MyDAO mock and use that for testing. Why bother with hibenrate emulation just mock out all the DAOs. What do you think ?
Thanks.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
查看“jmockit/samples/orderMngmntWebapp”示例测试套件中的
orderMngr.domain.customer.CustomerTest
,该套件可在 JMockit 完整发行版中找到。该测试类依赖于 Hibernate Emulation。 它可以通过“jmockit/build.xml”中的“sampleTests”目标运行。
我创建这个工具的动机主要是当项目有数百个映射实体时,SessionFactory 创建需要很长时间。 (在具有 400 多个实体类的项目中,大约需要 20-30 秒。)当然,这是在一套集成测试中。 对于一套单元测试来说,这个工具没有用。
这个想法是,开发人员可以在本地开发环境中快速运行集成测试来测试业务逻辑而不是持久性,同时让自动化构建服务器定期运行完整的测试套件,而无需模拟。
请注意,使用 Hibernate 模拟时仍会测试 HQL 查询。 假实现将解析 HQL 字符串并对内存中“持久化”的实体实例执行查询。 但 O/R 映射信息被忽略。
模拟 DAO 也是完全有效的,但是您的测试将永远不会真正测试 O/R 映射、HQL 查询或实际的数据库访问。 使用 Hibernate Emulation,您无需创建模拟,但可以在提供类似于内存数据库的功能的假 Hibernate 实现上运行测试。
Check out
orderMngr.domain.customer.CustomerTest
in the "jmockit/samples/orderMngmntWebapp" sample test suite, found in the JMockit full distribution.This test class relies on Hibernate Emulation. It can be run through the "sampleTests" target in "jmockit/build.xml".
My motivation for creating this tool was mainly that SessionFactory creation takes too long when the project has hundreds of mapped entities. (It took about 20-30 seconds in a project with 400+ entity classes.) This in a suite of integration tests, of course. For a suite of unit tests this tool is not useful.
The idea was that a developer could quickly run the integration tests in a local development environment to test business logic but not persistence, while letting the automated build server run the full test suite regularly, without emulation.
Note that HQL queries are still tested when using Hibernate emulation. The fake implementation will parse HQL strings and execute the query against entity instances "persisted" in memory. O/R mapping information is ignored, though.
Mocking DAOs is perfectly valid as well, but then your tests will never actually test the O/R mapping, HQL queries, or actual database access. Using Hibernate Emulation you don't create mocks, but can run the tests over a fake Hibernate implementation that provides something similar to an in-memory database.