Hello Edgar,

I already am using StrutsTestCase to tests
Actions I write.  I see how that could be
used to test whether validation works, but
unless I'm missing something testing of
custom validators this way would really be
just a side-effect of testing Actions.

So imagine you have an Action A that uses
Validator V.  I write a STC-bases unit test
and run it.  It passes, no problems.  One
day somebody modifies A to stop using V and
modifies V and breaks it.

My STC-bases tests keep running and passing,
because A still works, but I will never find
out that V is broken, because V is never
really tested directly.

A new developer is hired and writes a new
Action, AA, and decides to use V.  V is
broken and his AA class is now broken
because V is kaput.

One could argue that AA should have its unit
tests, too, and that those should show me
that V is (has been) broken....

So I will use STC for testing the Validator,
too, but I'm wondering if there is better,
more direct way of testing them?
I can test them directly when they are
Struts-independent, but when they depend on
Struts (e.g. by taking some Struts classes
as params), then I cannot.

Thanks,
Otis




---- On Wed, 26 Feb 2003, Edgar P. Dollin
([EMAIL PROTECTED]) wrote:

>  
> > Use StrutsTestCase,
http://strutstestcase.sourceforge.net.  
> > It does the whole struts cycle and
allows test of all struts 
> > components.
> > 
> > Edgar
> > 
> > > -----Original Message-----
> > > From: otisg [mailto:[EMAIL PROTECTED]
> > > Sent: Wednesday, February 26, 2003 4:51 PM
> > > To: '[EMAIL PROTECTED]'
> > > Subject: Q: Running unit tests for
Validator used with Struts
> > > 
> > > 
> > > Hello,
> > > 
> > > It is almost impossible to get anyone
> > > attention on struts-user.
> > > I'm using Struts and Validator with it.
> > > I wrote a custom Validator and want to
write
> > > a unit test for it.
> > > My Validator has a method like this:
> > > 
> > > public static boolean validateStartLetter(
> > >     Object bean,
> > >     ValidatorAction validatorAction,
> > >     Field field,
> > >     ActionErrors errors,
> > >     HttpServletRequest request
> > >     )
> > > {
> > >     String value =
> > > ValidatorUtil.getValueAsString(bean,
> > > field.getProperty());
> > >     if
> > >
((GenericValidator.isBlankOrNull(value)) ||
> > > !Character.isLetter(value.charAt(0)))
> > >     {
> > >         errors.add(field.getKey(),
> > > Resources.getActionError(request,
validatorAction, field));
> > >     }
> > > 
> > >     return errors.isEmpty();
> > > }
> > > 
> > > I am running JUnit from Ant to run my unit
> > > test class.
> > > Apparently this doesn't work because the
> > > instance of ActionErrors passed to this
> > > method is null, causing a NPE.
> > > 
> > > I wanted to check the unit tests for
> > > Validator in Struts (FieldChecks) to
see how
> > > you wrote your unit tests, so that
this NPE
> > > is avoided, but I could not find any unit
> > > tests for it.
> > > Are there really no unit tests there?
> > > 
> > > Regardless, how would you go about running
> > > unit tests for a custom validator from
> > > something like Ant?
> > > 
> > > It seems to me that doing that may be
> > > impossible, because there is no Struts
> > > running to instantiate ActionErrors, there
> > > is no HttpServletRequest, and so on.
> > > 
> > > Is there a way to do this?
> > > 
> > > Thanks,
> > > Otis
> > > 
> > > 
> > >
________________________________________________
> > > Get your own "800" number
> > > Voicemail, fax, email, and a lot more
http://www.ureach.com/reg/tag
> > > 
> > > 
> >
---------------------------------------------------------------------
> > > To unsubscribe, e-mail:
[EMAIL PROTECTED]
> > > For additional commands, e-mail:
[EMAIL PROTECTED]
> > > 
> > 
> 
> 
>
---------------------------------------------------------------------
> To unsubscribe, e-mail:
[EMAIL PROTECTED]
> For additional commands, e-mail:
[EMAIL PROTECTED]
> 
> 
> 


________________________________________________
Get your own "800" number
Voicemail, fax, email, and a lot more
http://www.ureach.com/reg/tag

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

Reply via email to