On 3/9/06, gomathi <[EMAIL PROTECTED]> wrote:
> Hi
> how to test java application in junit.Is there is any example for test.how to
> give each class into junit for testing

The MailReader application for Action 1.3 is a fair example of how to
approach unit testing in a web application environment.

* http://svn.apache.org/dist/struts/apps/v1.3.0/

Note that this is only a test-build, not a stable release.

The MailReader application uses a set of Plain Old Java Objects
(POJOs) to represent the business logic. These have their own tests,
and, in fact, live in a separate distribution that can be shared by
multiple appications.

* http://svn.apache.org/viewcvs.cgi/struts/apps/trunk/mailreader-dao/

(Right now, the MailReader business logic isn't available as a
separate distribution. To get the source, you'd have to check it out
of Subversion: http://struts.apache.org/downloads.html#Source_Code ).

This is the key: Strongly separate your business logic so that it is
clearly a separate project. Look at the web pages as a client for your
business logic. Then look at the unit tests as *another* client.
Design the pages, to determine the use cases, then write the business
logic, test the logic in isolation (using JUnit), and then call the
business logic from your web applications. All the Actions should do
is gather input for your business classes, call the business classes,
and analyze the result (success or failure).

As you plug the business logic into Actions, you can can use tools
lioke WebCanoo to test the page flow.

* http://webtest.canoo.com/webtest/manual/WebTestHome.html

There's also an example of doing that in the MailReader application.

Not for nothing, the book JUnit in Action starts out from square one,
and goes on to discuss testing some of the hairier aspects of web
development, including tag libraries.

* http://www.amazon.com/exec/obidos/tg/detail/-/1930110995/apachesoftwar-20/

I worked on this book with Vincent Masool, but it's really his book.
And, I'm happy to say, #69 on the JavaLobby Reader Choice list.

* http://www.javalobby.org/articles/5books/full.jsp

In the free zone, there are several online articles on the topic of
unit testing Struts applications. Here are a few links cribbed from
Struts Central.

* 
http://www.onjava.com/pub/a/onjava/2005/10/26/test-driven-development-using-strutstestcase.html

* http://www-128.ibm.com/developerworks/java/library/j-stc/

* http://www.onjava.com/pub/a/onjava/2004/09/22/test-struts.html

* http://www.javaworld.com/javaworld/jw-08-2004/jw-0830-testing.html

* http://www.devx.com/Java/Article/20198

* http://www.devx.com/Java/Article/17908/0

* http://javaboutique.internet.com/tutorials/StrutsTestCase/

-- HTH, Ted.
** http://husted.com/ted/blog/

---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to