James Mitchell wrote:

> ----- Original Message -----
> From: "Robert Leland" <[EMAIL PROTECTED]>
> To: "Struts Developers List" <[EMAIL PROTECTED]>
> Sent: Wednesday, February 12, 2003 2:00 PM
> Subject: Re: New Tests
>
>
>
>> Martin Cooper wrote:
>>
>>> I prefer this second approach, because then we're testing the real
>
>
> behaviour
>
>>> of the tags in a real container. Using a mock approach makes me nervous
>>> because of the intricacies of tag lifecycles, and I wouldn't feel as
>>> confident that the tags would work in the real world just because they
>>> worked in a mock environment. I too can live with the cost of page
>>> compilation time, traded against a better assurance that the tags are
>
>
> being
>
>>> properly tested.
>>>
>>> I do, however, agree with David that we need to test the tags in
>
>
> isolation.
>
>> I have 0 experience with Cactus,
>>
>> For the 1st. Method, Is there anyway you could harness the digester
>> to create a testing harness for the tags ?
>>
>> The digester xml would populate the Mock session/request, and the Tags
>> itself ?
>> It would even have the expected values from JUnit asserts.
>> That way the java code written hopefully could be minimized.
>>
>> And new tests would be cut and paste of java code and some small
>> changes.
>>
>
>
> Now that's an interesting idea. Care to elaborate?


Your conversation made me think of it....
Just that you need to initialize the Mock objects to setup each
test, so why not use the digester to create the mock objects.

You'd have to create the objects that are stored in the session first,
assuming they are simple bean objects creating them is easy.
Next comes the tricky part, mainly because I am not familar with the
digester. You could always use java code to set the request/session attributes, but could the digester do that some how ? Taking the
created objects and performing the setAttribute() calls ?
When using the digester is there some way to tag an object that when
it is created referred to by a string identifier ? Then later in the digester rules, use that object in a method call to do a setAttribute() ?
{Now modifying a struts-config.xml, and showing my ignorance of Digester}
Take for example
<james-tests>
<test-beans>
<test-bean name="simpleTestBean"
type="org.apache.struts.test.TestSimpleBean">
<test-property name="username" type="java.lang.String"/>
<test-property name="password" type="java.lang.String"/>
</test-bean>
</test-beans>

<!-- requests are not nested inside sessions, so they can be reused
across multiple session tests. When reused across tests they are always
reset to their initial values. Much like JUnit setup and teardown
operations. -->
<requests>
<request name="simpleRequest"
type="javax.servlet.http.HttpRequest">
<session-property name="attribute" type="java.lang.String" object="simpleTestBean"/>
<request>
</requests>

<sessions>
<session name="simpleSession"
type="javax.servlet.http.HttpSession">
<session-property name="attribute" type="java.lang.String" object="simpleTestBean"/>
</session>
</sessions>

</james-tests>

The object attribute tells the digester, or code that uses the digester, to look at the objects it has already created and call named javabean
setter, in this case setAttribute().


That would seem like at least the drudger of setting up your
unit tests could be automated some. Perhaps Cactus already does
this, it seems like a logical approach, either with digester, or betwixt
or something else. I say betwixt because then the state of the sessions
and requests could then be dumped out to another xml file/stream and the results viewed or compared to the expected values.

-Rob







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

Reply via email to