Let me elaborate on this a little bit.

When I write unit tests, I want to test my code efficiently.

I don't want to test:

- the JDBC API
- the database driver
- the database core with its caches, file system abstractions, ...
- creating a new database
- executing DDL code to create tables, indexes and other stuff
- loading test data into the new tables
- connecting to the test database
- copying test data around in memory
- converting the test data into a ResultSet
- parsing the ResultSet into a Record.
- erasing test data and replacing it with new test data for the next test
- ...

All these dependencies cost time, rarely give me additional value (like 
finding I'm using the wrong query or the query won't return the expected 
result, etc.) and they are hard to maintain. Instead of having everything 
in one place, I need to maintain a dozen different files, I need to find a 
way to make Spring lazy create the database when I need a different set of 
test data per test, etc.

Usually, I have these kinds of tests:

   1. Is my query correct syntactically?
   2. Does my query return the correct results?
   3. Does the code processing the results work correctly?
   4. Does my code update the database correctly?

The first kind of test is almost futile with jOOQ. I sometimes do it anyway 
for complex queries but I rarely run them versus the database. Instead, I 
let the test print the query, execute it once on an SQL tool and when it 
works, I copy the expected result into the test. There is no need to 
actually execute that query unless it changes.

The second test obviously needs a database but a static one. I can share 
same database among all the "test query results" tests since the queries 
don't change it. The cost to create the database is shared among all tests. 
If I run one individual test, then it's a bit expensive but I can bear with 
that. I can also make the database clever and persist it on disk, so I can 
omit many of the expensive steps above. So this isn't a problem or at a 
problem that I don't have a better solution for.

#3 only needs a database because ResultSet is such a horrible interface. 
It's usually more simple to just create a database than write 1000 lines of 
code just to be able to start writing my test.

But jOOQ doesn't really need ResultSet. It should be possible to pass it a 
mock connection that simply doesn't do anything (just a few lines of code 
to implement the few methods in java.sql.Connection).

And then I need a way to overwrite 
`org.jooq.impl.AbstractResultQuery.execute(ExecuteContext, 
ExecuteListener)` and I've cut a dozen unnecessary dependencies from my 
test cases.

A simple and API clean way to implement this would be to make the execute 
methods part of the configuration, maybe an Executioner interface which I 
can replace.

Regards,

A. Digulla

-- 
You received this message because you are subscribed to the Google Groups "jOOQ 
User Group" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
For more options, visit https://groups.google.com/groups/opt_out.


Reply via email to