lundi 11 avril 2016

Java testing with hsqldb when sql queries differ in production

I am working on a project using Oracle DB as the production database. To enable fast testing, we used HSQLDB for the local environment and wrote test cases for the same.

The main problem is that my primary DB query is :

PreparedStatement ps = conn.prepareStatement("SELECT * FROM STUDENTS WHERE ROLL_NO IN (?)");

and I supply this list in my db tests as

ps.setArray(rollNumbers);

However, for hsqldb, I need the following query:

SELECT * FROM STUDENTS WHERE ROLL_NO IN (UNNEST(?))

My test cases work in local but to test on production I will have to change them manually (and thus, break local cases). What's the best way to handle such a situation? I am working with legacy code and thus, can't use dependency injection directly (the code is called by external components with set params).

I considered subclassing the DAO inside junit and changing the queries there. But is that the right way? Or Should I use inflection api? How do you guys handle this?

Aucun commentaire:

Enregistrer un commentaire