Search code examples
javaspringpostgresqltestingh2

How to perform unit tests with h2 database where bpchar is used?


I have a spring + hibernate application that uses postgres database. I need to write unit tests for the controllers. For tests I wanted to use h2 database but unfortunately test crashes during create-drop leaving me with information that bpchar data type is invalid. I wonder how to solve this issue so I could run tests.

I can't change my columns with bpchar to varchar, it need to stay as it is. I also tried to set postgresql mode but it didn't helped. Am I right that the only solution I have is to use embedded postgres database in order to perform tests or is there any other approach that I could use?


Solution

  • Am I right that the only solution I have is to use embedded postgres database in order to perform tests or is there any other approach that I could use?

    You try to use postgres-specific data type with h2 (which does not have it). Of course, it does not work.

    If you cannot change type of this field - use embedded postgres in tests.