How to test persistence layer of a web based application?
Joined: Sep 15, 2003
Hi, We have a web based application(packaged as ear) running in Weblogic 7.0.
I want to write a suite of tests to test our persistence operations. The persistence layer is implemented as DAO's. There are no EJB's in the application.
How can I invoke these DAO classes packaged in the EAR to test them? What are the options(frameworks)?
Thanks in advance.
Joined: Nov 05, 2004
As long as your DAO's are well-defined and all your persistence code is in DAO's, you should be able to use JUnit to test your persistence layer
Joined: Sep 15, 2003
Hi Jayesh, Thanks for the respose. I do have the following additional question, How can I invoke the DAO (a plain java class) that is in the .ear from outside of weblogic? The DAO is not in a session bean.
Any links to examples or resources to how this can he done will be highly helpful.
Joined: Jan 23, 2002
Originally posted by p intelli: How can I invoke the DAO (a plain java class) that is in the .ear from outside of weblogic? The DAO is not in a session bean.
You can't, unless you expose the DAO to the outside world using some kind of an adapter like RMI, EJB, web services, servlet, etc.
Personally, I would Unit test the DAO outside your web server. You are trying to make the DAO reuseable, right? This means that they should run in standalone apps too, right? So, If I were you I would test my persisitence layer in a standalone JUnit app
Joined: Dec 27, 2003
I have a related question. I have a DAO with several methods. I want to write a suite of tests to test the success and failure of each of these methods. My DAO is written so that it is passed a DataSource object in its constuctor and it can create a Connection object from that DataSource.
How do I create a DataSource in JUnit so that I can test the DAO? Would I have to use Cactus? How would I create the DS in cactus?
hi, looks like my question is also alike i ahve an application with mvc desing pattern Controller - > helper class - > Dao Implementaion i was writing test cases for helper classes. but the helper class calls the dao implementaion and in the dao implementaion i am using the data source to get connection. when i run the test on my machine it fails since the daoimpl looks for the data source. Wondering how to write test cases for helper classes any help to any article will be appreciated. Thanks Rashid
Rashid, When unit testing the helper class, you want to test just that class. So you would create a mock DAO. What does the helper class do? Think about what it is responsible for to figure out what you are trying to test.
If you were writing a test for the DAO, you would create a mock datasource.
Joined: Feb 13, 2004
Thanks Jeanne my source code is organised as follows src->com->eds->met->Helper->all Helper Classes example ValueHelper.java src->com->eds->met->persistence->all Dao classes. Now the thing is if i have to write a mock dao where should i write it i have the following test folder structure in exact manner as the source from the root directory test->com->eds->met->Helper->ValueHelperTest.java In the ValueHelperTest i have all the test cases defined for ValueHelper class. In the setUp and teardown method i instantiate the valueHelper object and call the method. if i write my own mock Dao where should i write it. Please let me know Thanks...