使用junit + spring测试DAO文件

时间:2012-09-12 14:45:24

标签: java spring testing junit dao

我正在尝试使用junit测试DAO文件。有没有办法比较用2种不同方式执行的同一查询?

junit是否提供了一种使用两种方式访问​​数据库的机制?

3 个答案:

答案 0 :(得分:1)

使用spring和junit对数据执行断言有很多不同之处。 这是一个起点:

@RunWith(SpringJUnit4ClassRunner.class)
@ContextConfiguration(locations = {"classpath:applicationContext-test.xml"})
@Transactional
public abstract class BaseIntegration {

然后你的测试类可以扩展它,只是正常使用dao,并对任何数据执行断言。

答案 1 :(得分:0)

您可以使用Assert类

中的方法比较查询结果

答案 2 :(得分:0)

要测试DAO,您可以使用DBUnit