We are working on junit test and want to isolate the database dependency. So we are thinking to use in-memory database to replace the mysql database. There are some in-memory databases we could use like H2 database, HSQL. My question is: 1. Can H2 or HSQL perfectly replace mysql without any hidden trouble? Because there are might be some differences in the sql syntax. 2. I want to know if there are better choice to replace mysql database when we work on unit test?
Asked
Active
Viewed 2,557 times
0
-
Because there is no such in-memory db fully compatible with mysql, We decided to turn to docker based mysql. – leo Jun 26 '16 at 14:57
-
I know it is an old question but I'm asking out of curiosity. Were you using JPA/hibernate? If so, why would different databases for test and production profile matter anymore? – Morteza Sep 18 '20 at 21:19
-
Does this answer your question? [Is there a way to run MySQL in-memory for JUnit test cases?](https://stackoverflow.com/questions/6734410/is-there-a-way-to-run-mysql-in-memory-for-junit-test-cases) – Ravi Parekh Sep 15 '21 at 13:27
-
[In memory mysql/postgres DB](https://stackoverflow.com/a/66259759/410439) – Ravi Parekh Sep 15 '21 at 13:27
1 Answers
1
Databases such as HSQLDB do not behave exactly like MySQL. The advantage of testing with HSQLDB is to flag some of the unintended errors in your code which might pass under MySQL. For example some invalid aggregate queries work under MySQL but not HSQLDB.

fredt
- 24,044
- 3
- 40
- 61