How to initialise and create a ResultSet and Record in Jooq?

烂漫一生 提交于 2019-12-11 04:33:32

问题


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

Thanks in advance.


回答1:


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.

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);

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.



来源:https://stackoverflow.com/questions/14452596/how-to-initialise-and-create-a-resultset-and-record-in-jooq

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!