Hi,

I use HttpUnit, which is just an extension to JUnit. Below I added some of 
the test code for the first page of my demo application. The first (home) 
page has to input fields for user id and password and a submit button. If 
the right login is typed in the user proceeds to the second page (called 
congratulation page).  The first test (testHomePage) just checks whether 
the HomePage will be shown, when  the basic URL of my application is 
requested. Therefore my page contains a component that inserts the title of 
the page and takes it from the static field title of my HomePage class, 
which is the specification class of the home page.

I stated testing with HttpUnit a few weeks ago and I think that this is a 
very good way to test the overall functionality of your application. 
Certainly it would be good to have a really component based testing tool, 
but that would be diffiicult to write.  Within my tests by now I access the 
components with their id, as you can see below 
'...getFormWithId("formLogin");'
I think it is a good idea to have the ids set automatically. I cannot image 
a situation where you want to set your own id in the html code. By the way: 
couldn't there be a possiblity to switch the id setting on and off, mayby 
within the .application file?

I set up a testresource conatining my jetty and the connection to my db4o 
database. This setup will last for one test or for one test suite if you 
have one.  This is working really good and the tests are quite fast.

Best regards,

  Christian


------------ code of HomePageTest starts here ------------------------

package com.daedalos.tapestry.viewController.test;

import java.io.IOException;
import java.net.MalformedURLException;

import org.xml.sax.SAXException;

import com.daedalos.tapestry.database.DataBase;
import com.daedalos.tapestry.model.MyUser;
import com.daedalos.tapestry.viewController.CongratulationPage;
import com.daedalos.tapestry.viewController.HomePage;
import com.meterware.httpunit.GetMethodWebRequest;
import com.meterware.httpunit.WebConversation;
import com.meterware.httpunit.WebForm;
import com.meterware.httpunit.WebRequest;
import com.meterware.httpunit.WebResponse;

public class HomePageTest extends ViewControllerTestCase {

        String userId;

        public HomePageTest(String name) {
                super(name);
        }

        public void testHomePage() throws Exception {

                WebConversation wc = new WebConversation();
                WebRequest request =
                        new 
GetMethodWebRequest("http://localhost:8044/daedalos/verleihnix";);
                WebResponse homePage = wc.getResponse(request);
                this.assertEquals("Titel falsch", HomePage.title, 
homePage.getTitle());
        }

        public void testRightLogin() throws Exception {

                WebConversation wc = new WebConversation();
                WebResponse expectedToBeCongratulationPage =
                        proceedFromHomePageToCongratulationPage(wc);
                this.assertEquals(
                        "wrong page",
                        CongratulationPage.title,
                        expectedToBeCongratulationPage.getTitle());
        }


        public void testWrongLogin() throws Exception {

                WebConversation wc = new WebConversation();
                WebResponse homePage = 
wc.getResponse("http://localhost:8044/daedalos/verleihnix";);
                MyUser.hinzufuegen("Walter", "znerg");
                DataBase.closeConnection();
                WebForm form = homePage.getFormsWithID("formLogin");
                WebRequest request = form.getRequest();
                request.setParameter("inputUserid", "Walter");
                request.setParameter("inputPassword", "rwerwueo");
                WebResponse expectedToBeHomePage = wc.getResponse(request);
                this.assertEquals("wrong page", HomePage.title, 
expectedToBeHomePage.getTitle());
        }

       public String getUserId() {
                return userId;
        }

        public void setUp() throws Exception {
                userId = "Hans";
                JettyTestResource.getSingleInstance().start();
                DataBase.setTestDatabase();
                new File(DataBase.getFileName()).delete();
                connection = DataBase.getConnection();
                MyUser.hinzufuegen(userId, "znerg");
                DataBase.closeConnection();
        }

        public void tearDown() {
                DataBase.closeConnection();
                DataBase.setProductionDatabase();
        }

        public WebResponse 
proceedFromHomePageToCongratulationPage(WebConversation wc)
                throws MalformedURLException, IOException, SAXException {

                WebResponse homePage =
 
wc.getResponse("http://localhost:8044/myWebUrl/myAppUrl";);
                WebForm form = homePage.getFormWithID("formLogin");
                WebRequest request = form.getRequest();
                request.setParameter("inputUserid", userId);
                request.setParameter("inputPassword", "znerg");
                WebResponse expectedToBeCongratulationPage = 
wc.getResponse(request);
                return expectedToBeCongratulationPage;
        }


}


----- end of code --------------------------------------




Daedalos Consulting GmbH
www.daedalos.com
[EMAIL PROTECTED]


-------------------------------------------------------
This sf.net email is sponsored by:ThinkGeek
Welcome to geek heaven.
http://thinkgeek.com/sf
_______________________________________________
Tapestry-developer mailing list
[EMAIL PROTECTED]
https://lists.sourceforge.net/lists/listinfo/tapestry-developer

Reply via email to