单元测试Hibernate驱动的应用程序? [英] Unit testing a Hibernate driven application?

查看:96
本文介绍了单元测试Hibernate驱动的应用程序?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这可能是一个天真的问题,但我对junit和hibernate框架都很陌生,我想知道什么是单元测试主要调用hibernate的应用程序的最佳方法,或者甚至需要这样做?



这里的最佳做法是什么?

编辑:

春天似乎是这里的重大建议。不幸的是,对于一个项目来说,这可能太多了。 Junit,Hibernate和Spring对我来说都是新的,虽然他们都是我想要得到的技术,但我认为试图将它们整合到一个项目中可能对我来说太过压倒。


欢迎指导教程和/或书籍建议。

测试和集成测试。

单元测试应该测试没有任何外部依赖的代码。使用像JMock这样的框架来模拟这些依赖关系。

集成测试也很重要,但它们的主要缺点是它们需要很长时间才能运行。您可以在几秒钟内运行数千次真正的单元测试,但与集成测试不同。

根据您的项目/开发团队的规模,您可能希望优先考虑集成测试的真正单元测试。这两种测试风格都很重要,但如果你对资源的要求很高,那么单单测试可能是一个更好的主意。

我自己写了一个应用程序,单元测试了Web(使用Spring MVC这很简单)和服务层以及域对象。但是我离开了DAO,因为我不想写一堆慢速集成测试。如果我有更多员工,我也会进行集成测试,但在这种情况下,我并不觉得花费的时间是值得的。


This may be a naive question, but I am new to both the junit and hibernate frameworks and I was wondering what the best way to go about unit testing an application that is largely calls to hibernate, or if it is even necessary to do so?

What is the best practice here?

EDIT:
Spring seems to be the big suggestion here. Unfortunately this may be alittle too much to bite off for one project. Junit, Hibernate and Spring are all new to me, and while they are all technologies I want to get under my belt, I think trying to incorporate them all into one project may be too overwhelming for me.

Links to tutorials and/or book suggestions are welcome.

解决方案

Keep in mind the difference between unit testing and integration testing.

Unit tests should be testing code without any outside dependencies. These dependencies are mocked using a framework like, for example, JMock.

Integration tests are important too but the major drawback of them is that they take a long time to run. You can run thousands of true unit tests in a couple of seconds, but it's not the same with integration tests.

Depending on the size of your project/development team you might want to prioritize true unit tests over integration tests. Both style of tests are important but if you are pressed for resources, just going with Unit testing may be a better idea.

I wrote an application by myself that unit tested the Web (with Spring MVC this is easy) and Service layers, as well as domain objects. But I left the DAO alone because I didn't want to write a bunch of slow integration tests. If I had more people on staff I would have gone with integration tests as well, but in this case I didn't feel the time spent would be worth it.

这篇关于单元测试Hibernate驱动的应用程序?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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