如何在Jooq中初始化和创建ResultSet和Record? [英] How to initialise and create a ResultSet and Record in Jooq?

查看:352
本文介绍了如何在Jooq中初始化和创建ResultSet和Record?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我需要编写一些单元测试,以便模拟结果集并使用一些虚拟数据进行记录.我不知道如何初始化和实例化它们.请帮助

I need to write some unit tests for that I have to mock the Result set and Record with some dummy data. I don't know how to initialize and instantiate them. Please help

谢谢.

推荐答案

jOOQ具有一些内置的模拟功能,请参见

jOOQ has a few built-in mock features, see the chapter JDBC mocking for unit testing of the manual, it might be what you are looking for.

但是,只需创建jOOQ的ResultRecord,您可以使用DSLContext:

However, to simply create a jOOQ's Result or Record, you may use the DSLContext for that:

// Create the record using the jOOQ generated classes and set a property
MyTableRecord record1 = DSL.using(configuration).newRecord(MY_TABLE);
record1.setValue(MY_TABLE.MY_PROPERTY, "value");

// or simply...
MyTableRecord record2 = new MyTableRecord();
record2.setMyProperty("value");

// Then you can populate the Result
Result<MyTableRecord> result = DSL.using(configuration).newResult(MY_TABLE);
result.add(record1);
result.add(record2);

您还提到了ResultSet,如果您是说JDBC ResultSet,那么模拟它可能会有些复杂.相反,我建议 DbUnit ,这不是JDBC类的模拟,但您将协助您设置测试数据库,可以帮助您获得与模拟JBDC类相同的效果.

You also mention ResultSet, if by that you mean the JDBC ResultSet, then it might be a bit more complicated to mock that. Instead, I would suggest DbUnit, that is not a mock for JDBC classes, but you'll assist you to setup your database for tests, which might help you to get the same effects you would have by mocking JBDC classes.

这篇关于如何在Jooq中初始化和创建ResultSet和Record?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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