File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Struts and the fly likes unit testing struts? Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Frameworks » Struts
Bookmark "unit testing struts?" Watch "unit testing struts?" New topic
Author

unit testing struts?

Jessica Sant
Sheriff

Joined: Oct 17, 2001
Posts: 4313

So what do you folks use to unit test your struts app?

StrutsTestCase? (Mock object approach or Cactus approach?)
HttpUnit?
plain Cactus?

I've got a typical Struts app with a DB backend, so can I really test it with Mock objects if I need to be able to ping the DB for data? BTW, I never insert data in the DB with my app, its all just viewing data that already exists in the DB.


- Jess
Blog:KnitClimbJava | Twitter: jsant | Ravelry: wingedsheep
Chris Mathews
Ranch Hand

Joined: Jul 18, 2001
Posts: 2712
Personally, I find little need to unit test Struts Action because I do my best to keep business logic out. I try to use Actions just for page flow...
Jessica Sant
Sheriff

Joined: Oct 17, 2001
Posts: 4313

ahhh good point -- all my business logic is in my "helper" methods -- so I guess I can just do straight JUnit tests on those to test. Although I guess I'll need to use some mock objects to handle request / session scopes and stuff, right?
Tim Brizard
Greenhorn

Joined: May 14, 2004
Posts: 4
Jess,
In the past I've used a BusinessDelegate(s) which gets called from my Action class(s). The business delegate does not know anything about servlet classes or struts classes. So, I can write my junit tests without having to create Mock objects, just test the business functionality that is exposed by the methods on the business delegate(s). The business delegate, then uses whatever other classes you have designed (Session Facade, BOs, etc.). This way there is little testing of the Action class that is needed, because you would essentially be testing the Struts Framework. Hope this helps.
[ May 14, 2004: Message edited by: Tim Brizard ]
Srikanth Shenoy
author
Ranch Hand

Joined: Jan 24, 2004
Posts: 184
Jess,

I agree with what other people have had to say regarding testing Struts app.
The reason is the same: All the business logic gets tested in their respective JUnit methods.
The only tests that I do for my Struts classes is actually launch the browser to do a manual end-to-end testing - that too only when I write/modify that code.

However the reason for this is that the company I work for has QA team that records the regression test scripts using commercially available tools.

In the absence of such regression scripts, I think Struts Test case or equivalent might be needed.


On another note, does anybody know of a open source/free regression test recorders that has the capability of parameterization and assertion (like the commercial tools)?

Thanks.


Srikanth Shenoy
Author of Struts Survival Guide : Basics to Best Practices
Jeanne Boyarsky
internet detective
Marshal

Joined: May 26, 2003
Posts: 30512
    
150

Jess,
Like the others, I keep the business logic out of the action. I use mock objects (easy mock) to check getting/storing values in the session/request.


[Blog] [JavaRanch FAQ] [How To Ask Questions The Smart Way] [Book Promos]
Blogging on Certs: SCEA Part 1, Part 2 & 3, Core Spring 3, OCAJP, OCPJP beta, TOGAF part 1 and part 2
Lasse Koskela
author
Sheriff

Joined: Jan 23, 2002
Posts: 11962
    
    5
Since mister Holmes mentioned in another thread that the book covers unit testing Struts applications, I thought it would be beneficial to revive this thread...


Author of Test Driven (2007) and Effective Unit Testing (2013) [Blog] [HowToAskQuestionsOnJavaRanch]
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: unit testing struts?