Testing date values with HSQLDB

2019-08-15 19:04发布

问题:

We use SQLServer in production, but HSQLDB for our integration tests. HSQLDB is used because it's an in-memory database.

I have an SQLServer SQL that executes the following code:

select convert(varchar(8), pos_val_date, 112) 
from wscpos;

In HSQLDB, this does not work. The code should be:

select to_char( pos_val_date, 'YYYYMMDD')
from wscpos;

What's the best practice to adapt my code such that it runs both in production and in my integration test?

回答1:

If you are inclined to change your DB for integration tests, I would recommend to adopt H2 using MODE=MSSQLServer which should provide a better compatibility against MS SQL Server, better than what HSQLDB gives you now.