简体   繁体   中英

Hibernate/JPA without DB

Wondering if it is possible to get rid completely of SQL dependency. Let's say I'm writing test which communicates with DB, this introduces the need to manage DB schema, this is very cumbersome as in-memory DB often do not match to production type DBs.

Would it be possible to test with Hibernate/JPA and no underline DB Schema?

I know so far of two options, I'd like here to broaden my knowledge, if there are any other possibilities, please share.

  1. mock the hibernate
  2. use fake JDBC driver

Or should I just focus on mocking DAO layer and not wasting time with this at all? Sanity checking JPA entities vs DB is completely different story.

You fear the difference between an in-memory database and the production database? But you don't fear the much greater difference between your two "mock" options and production?

From my point of view any replacement of the production database for testing will create false positives somehow. And I would guess that an in-memory database will mimic the real environment best. Especially if you use something like H2 which tries to support different SQL dialects.

As long as you only write small and encapsulated unit tests a mock of your DAO layer may help as well. But as soon as you are writing integration tests you will need to provide a database somehow.

And no - Hibernate can't work without a database schema or connection.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM