You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@struts.apache.org by "Stasica, Grzegorz" <gr...@delphi.com> on 2006/05/05 12:05:45 UTC

FW: StrutsTestCase & Hibernate

hi,

Basically I'm interested in testing struts actions (forwards, messages
etc). Most of the actions perform some actions on my database which I'd
like to speed up. My idea is to isolate database tests from struts
action test. There is only one way to achieve it which I see at the
moment (mock objects). If I substitute my persistence layer in tests on
mocks not only tests will run faster but I'll not have to prepopulate
database for each test (even in memory datatabase needs some
configuration prior to tests). Unfortunately except idea I've nothing.
I've no idea on how to achieve it.
Any idea or sample code ?
I think the problem is not open and many of you've solved it in one way
or another



****************************************************************************************

Note:  If the reader of this message is not the intended recipient, or an employee or agent responsible for delivering this message to the intended recipient, you are hereby notified that any dissemination, distribution or copying of this communication is strictly prohibited. If you have received this communication in error, please notify us immediately by replying to the message and deleting it from your computer. Thank you.

****************************************************************************************

Re: FW: StrutsTestCase & Hibernate

Posted by Adam Hardy <ah...@cyberspaceroad.com>.
I think unit tests on everything are always a good idea - the problem 
comes if you start making them 'more' than just unit tests.

Ideally you should be able to unit test action classes quickly with mock 
objects or stubs for both the business tier below and the MVC controller 
tier above.

StrutsTestCase offers alot. I haven't used it but I believe it's easy 
enough to set up and run to mock the MVC part.

Then something like Spring could instantiate stubbed business objects 
instead of real ones, so that the actions can run happily against a back 
end. For that of course you'd need interface-based business objects.

It would be best to limit your tests to keep them fast and simple, but 
you could do any or all of the following tests:

(1) good input params result in the action forward you want
(2) bad input params result in an 'error' action forward
(3) a business exception in the business tier is handled ok
(4) a system exception in business tier results in an 'error' action forward

I wouldn't do any unit testing here that involved input parameter 
validation routines - i.e. i use Validator - I think that requires too 
much effort setting up the correct params for each unit test.

On a related note, I find it useful to run the ant or maven build with 
JSP compilation as well (by default it happens only in the container) 
just to make sure you don't get any ugly surprises after deploy.



Jakub Milkiewicz on 06/05/06 11:03, wrote:
> Hi
> If you are thinking of unit tests for action i do not think it is great
> idea.
> For me actions should be as dumb as possible and just delegate business
> processing to another layer.
> 
> 2006/5/5, Stasica, Grzegorz <gr...@delphi.com>:
>>
>> Basically I'm interested in testing struts actions (forwards, messages
>> etc). Most of the actions perform some actions on my database which I'd
>> like to speed up. My idea is to isolate database tests from struts
>> action test. There is only one way to achieve it which I see at the
>> moment (mock objects). If I substitute my persistence layer in tests on
>> mocks not only tests will run faster but I'll not have to prepopulate
>> database for each test (even in memory datatabase needs some
>> configuration prior to tests). Unfortunately except idea I've nothing.
>> I've no idea on how to achieve it.
>> Any idea or sample code ?
>> I think the problem is not open and many of you've solved it in one way
>> or another


---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
For additional commands, e-mail: user-help@struts.apache.org


Re: FW: StrutsTestCase & Hibernate

Posted by Jakub Milkiewicz <jm...@gmail.com>.
Hi
If you are thinking of unit tests for action i do not think it is great
idea.
For me actions should be as dumb as possible and just delegate business
processing to another layer.



2006/5/5, Stasica, Grzegorz <gr...@delphi.com>:
>
>
> hi,
>
> Basically I'm interested in testing struts actions (forwards, messages
> etc). Most of the actions perform some actions on my database which I'd
> like to speed up. My idea is to isolate database tests from struts
> action test. There is only one way to achieve it which I see at the
> moment (mock objects). If I substitute my persistence layer in tests on
> mocks not only tests will run faster but I'll not have to prepopulate
> database for each test (even in memory datatabase needs some
> configuration prior to tests). Unfortunately except idea I've nothing.
> I've no idea on how to achieve it.
> Any idea or sample code ?
> I think the problem is not open and many of you've solved it in one way
> or another
>
>
>
>
> ****************************************************************************************
>
> Note:  If the reader of this message is not the intended recipient, or an
> employee or agent responsible for delivering this message to the intended
> recipient, you are hereby notified that any dissemination, distribution or
> copying of this communication is strictly prohibited. If you have received
> this communication in error, please notify us immediately by replying to the
> message and deleting it from your computer. Thank you.
>
>
> ****************************************************************************************
>