I am getting list of data from database from my Service Class Method mDataVO.getMarketData() where mDataVO is an object of marketDataVO which is an value object for storing different types of data.
Inside my getMarketData(), i am making a Hibernate Query to get data out from the database. Now my goal is to unit test this data in my unit test class and make sure that am getting correct data our and returned data from method call is not stale and is same as latest value from the database.
For this purpose in my unit test class, i have used the same Hibernate Query and so am getting same set of data now this does not solve the purpose of unit testing as am just comparing same data which is obtained by running same query in the database. I am not sure how this case can be unit tested.
Am I missing out point of unit testing or not seeing any values in my
unit test case?
Update
Still question remains unanswered. Any more suggestions?
The problem with testing databases is, as you might guess, the data.
I think the way to attack this is to have a test database that matches your production schema. Do what you need to do to populate the database, test the data access objects, and then drop the test database.
Another approach is to create the data set that you know you should get, insert it into the database, do your query and make sure that the query result matches the data set, and then roll the whole thing back as one transaction. That way your test data is always fresh but you don’t do any harm to your database.
Test the database DAO for unit testing. Once it’s working, you should mock the DAO when you test the service. Unit testing the service means you aren’t worried about the DAO anymore. Just make sure that the service gets the data it needs to prove its proper operation.