CreateManager |
|
Your trail: |
Difference between
version 9
and
version 8:
At line 18 changed 1 line. |
Since we're continuing from [Part I|CreateDAO], let's create a JUnit test for the PersonManager. Create PersonManagerTest in the test/web/**/service directory. We'll want to test the same basic methods (get, save, remove) that our DAO has. This may seem redundant (why all the tests!), but these tests are GREAT to have 6 months down the road. |
Since we're continuing from [Part I|CreateDAO], let's create a JUnit test for the PersonManager. Create PersonManagerTest in the test/web/**/service directory. We'll want to test the same basic methods (get, save, remove) that our DAO has. This may seem redundant (why all the tests!), but these tests are GREAT to have 6 months down the road. This class should extend [BaseManagerTestCase|http://raibledesigns.com/downloads/appfuse/api/org/appfuse/webapp/service/BaseManagerTestCase.java.html], which already exists in the ''service'' package. The parent class (BaseManagerTestCase) serves the same functionality as the BaseDaoTestCase - to load a properties file that has the same name as your *Test.class. |
At line 21 added 3 lines. |
|
The code below is what we need for a basic JUnit test of our Managers. It created and destroys our PersonManager. The "conn" object is initialized (and obtains a connection) in the [BaseManagerTestCase|http://raibledesigns.com/downloads/appfuse/api/org/appfuse/webapp/service/BaseManagerTestCase.java.html] class. |
|
At line 62 added 6 lines. |
Now that we have the JUnit framework down for this class, let's add the meat: the test methods to make sure everything works in our Manager. Here's a snippet from the [DAO Tutorial|CreateDAO] tutorial to help you understand what we're about to do. |
|
;;''...we create methods that begin with "test" (all lower case). As long as these methods are public, have a void return type and take no arguments, they will be called by our <junit> task in our Ant build.xml file. Here's some simple tests for testing CRUD. An important thing to remember is that each method (also known as a test), should be autonomous.'' |
|
Add the following methods to your PersonDaoTest.java file: |
|
Back to CreateManager,
or to the Page History.
|