Reader small image

You're reading from  jOOQ Masterclass

Product typeBook
Published inAug 2022
Reading LevelBeginner
PublisherPackt
ISBN-139781800566897
Edition1st Edition
Languages
Tools
Right arrow
Author (1)
Anghel Leonard
Anghel Leonard
author image
Anghel Leonard

Anghel Leonard is a Chief Technology Strategist and independent consultant with 20+ years of experience in the Java ecosystem. In daily work, he is focused on architecting and developing Java distributed applications that empower robust architectures, clean code, and high-performance. Also passionate about coaching, mentoring and technical leadership. He is the author of several books, videos and dozens of articles related to Java technologies.
Read more about Anghel Leonard

Right arrow

jOOQ testing

Accomplishing jOOQ testing can be done in several ways, but we can immediately highlight that the less appealing option relies on mocking the jOOQ API, while the best option relies on writing integration tests against the production database (or at least against an in-memory database). Let's start with the option that fits well only in simple cases, mocking the jOOQ API.

Mocking the jOOQ API

While mocking the JDBC API can be really difficult, jOOQ solves this chore and exposes a simple mock API via org.jooq.tools.jdbc. The climax of this API is represented by the MockConnection (for mocking a database connection) and MockDataProvider (for mocking query executions). Assuming that jUnit 5 is used, we can mock a connection like this:

public class ClassicmodelsTest {
 public static DSLContext ctx;
 @BeforeAll
 public static void setup() {
  // Initialise your data provider
  MockDataProvider provider = new ClassicmodelsMockProvider();
 ...
lock icon
The rest of the page is locked
Previous PageNext Page
You have been reading a chapter from
jOOQ Masterclass
Published in: Aug 2022Publisher: PacktISBN-13: 9781800566897

Author (1)

author image
Anghel Leonard

Anghel Leonard is a Chief Technology Strategist and independent consultant with 20+ years of experience in the Java ecosystem. In daily work, he is focused on architecting and developing Java distributed applications that empower robust architectures, clean code, and high-performance. Also passionate about coaching, mentoring and technical leadership. He is the author of several books, videos and dozens of articles related to Java technologies.
Read more about Anghel Leonard