Tuesday, March 19, 2013

Use jOOQ to mock JDBC

When you want to do unit tests for the DB access layer of a project, you may need to mock JDBC API.  But it will be an awkward work if you do it with common Mock frameworks like JMock or Mockito.  At that moment, you can consider use jOOQ to do that.

jOOQ is a Java framework to help you to write type-safe SQL DML (there is a similar framework named QueryDSL.  But it is more powerful than jOOQ).  And it shipped with a JDBC mock class collection.  With these classes, you can mock JDBC API for your DB layer UT.

You can view the reference of jOOQ for details: JDBC mocking for unit testing.

No comments:

Post a Comment