How to effectively test SQL / JPQL / HQL?

Often when testing a device for dont test the database as that is an integration test ( see point 4 ).

However, SQL / JPQL / HQL encapsulates the data store specific logic, which is often in a line format about how to access data. This free-form string access command can easily be mistaken and therefore needs testing.

How to effectively test such logic?

+4
source share
2 answers

Closest you can run unit test at the request of SQL (or a similar structure) to configure the SQLite database in memory and execute it.

While this is still technically an integration test, it runs almost as fast as the unit test should.

If you do, just notice the slight differences between SQLite and your real database, and try to make your queries compatible with both.

Hope this helps,
Assaf.

+2
source

This is not a unit test, but there is nothing using a unit testing system like Nunit to test your sql. But it is important that you separate it from real unit tests. Real unit tests are quick and do not communicate with the external ... and they do not try to change it with updates, deletions and inserts.

+1
source

All Articles