Rajeev Akotkar
Rajeev Akotkar

Reputation: 1397

Hibernate :Testing Daos

My project is a legacy project with core java and hibernate.No unit tests are written over here.What can be best strategy for testing in this scenario?

P.S. If i use mockito then I wont be able to test my queries ,so I dont want to use any Mock test framework (e.g. Mockito, EasyMock ,PowerMock) etc. I can write junits but they will be again hitting my real db.I have considered using in memory db.

Upvotes: 0

Views: 47

Answers (1)

Ivan Lymar
Ivan Lymar

Reputation: 2293

It's common approach to use in-memory DBs for writing DB tests ( they considered to be integration tests though ). But there are some pros and cons you need to take into consideration:

Pros:

You should not think about cleaning up.

You can setup DB in whatever way you need.

It's easy to handle such kind of working environment. You don't need to install anything additional.

Cons:

DB that you use for testing is different.

Transactions may not work.

DB objects may not work.

Some sql constructions may not work.

So taking into consideration all cons, I would suggest using docker containers with DB installed inside. Each time you will have clean db, you should not care about data clean up and furthermore this will be exactly same DB as you have in prod.

Upvotes: 1

Related Questions