Question

I wrote a method that retrieves certain list of strings, given a correct string key. Now when I create a list(the one to be retrieved by method descibed in previous sentence) and create test I can easily get results and test passes successfully.

Now on the other hand if I save the content of this list to database in 2 columns, key and value I wrote a class which retrieves this items with method inside it. And when I print it out to console the expected results are correct, now I initialize my DAO from application context where inside its bean it gets session and because of DAO works.

Now I'm trying to write a test which will mock the DAO, because I'm running test localy not on the server .. so I told jmock to mock it :

private MyDAO myDAO;

in the setup()

myDAO = context.mock(MyDAO.class);

I think I'm mocking it correctly or not, how can I mock this data from database? what is the best way?

Is there somewhere good Jmock documentation? on their official site its not very good and clear, you have to know what you seek in order to find it, can't discover something cool in the mean time.

OR can someone help me with this approach :

How can I create application context which I will use just for tests, to instansiate DAO and few beans there like on server. So I can use it in the tests? Also suggestions, explanation all is welcome . thank you

Was it helpful?

Solution

This and this posts describe how and why to test DAOs. (you can easily isolate spring and maven from the example, if you are not using them - the point is using HSQLDB)

OTHER TIPS

MyDAO is a interface, you only can make a mock of interfaces.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top