You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@struts.apache.org by Rusty Wright <ru...@gmail.com> on 2009/09/04 09:23:19 UTC

how do you test your action classes?

For example, how can I test the validations if I'm using an xml file with the validation specifications in it?  Seems like there are a lot of moving parts around the invocation of the action classes that make testing hard.

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


Re: how do you test your action classes?

Posted by phillips1021 <bp...@ku.edu>.
Rusty - Please post an example if you are able to use the Struts 2 JUnit
plugin.  


Rusty Wright-2 wrote:
> 
> I'm going to try the StrutsTestCase in struts2-junit-plugin; it looks like
> that may do the trick for me.
> 
> Thanks everyone for their feedback and links.
> 
> 
-- 
View this message in context: http://www.nabble.com/how-do-you-test-your-action-classes--tp25289507p25308130.html
Sent from the Struts - User mailing list archive at Nabble.com.


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


Re: how do you test your action classes?

Posted by Rusty Wright <ru...@gmail.com>.
I'm going to try the StrutsTestCase in struts2-junit-plugin; it looks like that may do the trick for me.

Thanks everyone for their feedback and links.


Greg Lindholm wrote:
> You probably should sure the mail archives (on Nabble) as this question come
> up very often.
> In fact it should be in a FAQ but there is some disagreement as what
> constitutes appropriate testing and what methods should be used.
> 
> I've written up this article [1] on how to unit test actions in the full
> Struts 2 context with the Interceptor stack and validations.
> 
> Others, seem to think this is the wrong approach and this type of testing
> should be done with a tool like Selenium.  Here is the last big thread on
> testing methods [2].
> 
> [1] http://glindholm.wordpress.com/2008/06/30/unit-testing-struts-2-actions/
> 
> [2]
> http://www.nabble.com/unit-testing-Struts2-application-%28with-Spring-and-Hibernate%29-ts24517800.html
> 
> On Fri, Sep 4, 2009 at 3:23 AM, Rusty Wright <ru...@gmail.com> wrote:
> 
>> For example, how can I test the validations if I'm using an xml file with
>> the validation specifications in it?  Seems like there are a lot of moving
>> parts around the invocation of the action classes that make testing hard.
>>
>> ---------------------------------------------------------------------
>> To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
>> For additional commands, e-mail: user-help@struts.apache.org
>>
>>
> 

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


Re: how do you test your action classes?

Posted by jaredtims <ja...@yahoo.com>.
Can anyone confirm that the Struts2 Convention Plugin will not work with the
Struts2 jUnit Plugin?  I am attempting to unit test my actions, but I keep
getting the following error:

2011-10-14 14:15:42,380 WARN 
org.springframework.mock.web.MockServletContext.getResourcePaths:212 -
Couldn't get resource paths for class path resource [WEB-INF/content/]
java.io.FileNotFoundException: class path resource [WEB-INF/content/] cannot
be resolved to URL because it does not exist

I'd rather not have to rewrite all my action mappings into xml files just
because the jUnit Plugin doesn't handle the Convention Plugin annotations?

--
View this message in context: http://struts.1045723.n5.nabble.com/how-do-you-test-your-action-classes-tp3495971p4903701.html
Sent from the Struts - User mailing list archive at Nabble.com.

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


Re: how do you test your action classes?

Posted by Musachy Barroso <mu...@gmail.com>.
yeah, I am not sure how to fix that one, we would have to figure out a
smart(hacky) way to make the servlet context resolve the paths, but
that would probably only work for maven.

musachy

On Thu, Sep 17, 2009 at 8:51 AM, phillips1021 <bp...@ku.edu> wrote:
>
> Musachy:
>
>  I'm using the code for the JUnit plugin (2.1.8) to do testing of Struts 2
> Actions.  My project is using the Spring and convention plugins.  The tests
> execute successfully, but a FileNotFoundException is thrown.  Here is the
> relevant log data when running the test.
>
> 2009-09-17 10:44:13,377 WARN
> org.springframework.mock.web.MockServletContext.getResourcePaths:212 -
> Couldn't get resource paths for class path resource [WEB-INF/content/]
> java.io.FileNotFoundException: class path resource [WEB-INF/content/] cannot
> be resolved to URL because it does not exist
>        at
> org.springframework.core.io.ClassPathResource.getURL(ClassPathResource.java:163)
>        at
> org.springframework.core.io.ClassPathResource.getFile(ClassPathResource.java:175)
>        at
> org.springframework.mock.web.MockServletContext.getResourcePaths(MockServletContext.java:196)
> at
> org.apache.struts2.convention.DefaultResultMapBuilder.createFromResources(DefaultResultMapBuilder.java:227)
>        at
> org.apache.struts2.convention.DefaultResultMapBuilder.build(DefaultResultMapBuilder.java:183)
>        at
> org.apache.struts2.convention.PackageBasedActionConfigBuilder.createActionConfig(PackageBasedActionConfigBuilder.java:680)
>        at
> org.apache.struts2.convention.PackageBasedActionConfigBuilder.buildConfiguration(PackageBasedActionConfigBuilder.java:479)
>        at
> org.apache.struts2.convention.PackageBasedActionConfigBuilder.buildActionConfigs(PackageBasedActionConfigBuilder.java:278)
>        at
> org.apache.struts2.convention.ClasspathPackageProvider.loadPackages(ClasspathPackageProvider.java:52)
>        at
> com.opensymphony.xwork2.config.impl.DefaultConfiguration.reloadContainer(DefaultConfiguration.java:200)
>        at
> com.opensymphony.xwork2.config.ConfigurationManager.getConfiguration(ConfigurationManager.java:55)
>        at
> org.apache.struts2.dispatcher.Dispatcher.init_PreloadConfiguration(Dispatcher.java:360)
>        at org.apache.struts2.dispatcher.Dispatcher.init(Dispatcher.java:403)
>        at
> org.apache.struts2.util.StrutsTestCaseHelper.initDispatcher(StrutsTestCaseHelper.java:54)
>        at
> edu.ku.it.si.blackboarddemo.action.StrutsTestCase.initDispatcher(StrutsTestCase.java:207)
>        at
> edu.ku.it.si.blackboarddemo.action.StrutsTestCase.setUp(StrutsTestCase.java:193)
>
> By default the convention plugin specifies that JSPs will be in
> WEB-INF/content/.
>
> I can send you a complete maven project with the test that demonstrates this
> issue.
>
> I'm using Spring plugin and convention plugin versions 2.1.6.
>
> Bruce
>
> Musachy Barroso wrote:
>>
>> JUnit plugin has been around as long as I can remember. What is new in
>> 2.1.8 is the ability to execute actions inside Struts and outside a
>> container.
>>
>> musachy
>>
>> On Sat, Sep 5, 2009 at 7:58 AM, phillips1021<bp...@ku.edu> wrote:
>>>
>>> Since Musachy mentioned that the code wasn't yet released I wasn't sure
>>> about
>>> the protocol.
>>>
>>> I'll take your comment as yes its OK.
>>>
>>> Will the Struts 2 JUnit plugin jar be part of the 2.1.8 release?  I'd
>>> like
>>> to include in my article if people can expect it in 2.1.8 and be able to
>>> just add a dependency in the pom.xml or include the downloaded jar in
>>> their
>>> classpath.  For now I understand they'll have to checkout the latest code
>>> from subversion repository.
>>>
>>>
>>>
>>> newton.dave wrote:
>>>>
>>>> phillips1021 wrote:
>>>>> is it OK if I write up a blog article with code example that shows
>>>>> how to use the StrutsTestCase right now for writing unit tests?
>>>>
>>>> Why wouldn't it be?
>>>>
>>>> Dave
>>>>
>>>>
>>>> ---------------------------------------------------------------------
>>>> To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
>>>> For additional commands, e-mail: user-help@struts.apache.org
>>>>
>>>>
>>>>
>>>
>>> --
>>> View this message in context:
>>> http://www.nabble.com/how-do-you-test-your-action-classes--tp25289507p25309276.html
>>> Sent from the Struts - User mailing list archive at Nabble.com.
>>>
>>>
>>> ---------------------------------------------------------------------
>>> To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
>>> For additional commands, e-mail: user-help@struts.apache.org
>>>
>>>
>>
>>
>>
>> --
>> "Hey you! Would you help me to carry the stone?" Pink Floyd
>>
>> ---------------------------------------------------------------------
>> To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
>> For additional commands, e-mail: user-help@struts.apache.org
>>
>>
>>
>
> --
> View this message in context: http://www.nabble.com/how-do-you-test-your-action-classes--tp25289507p25491968.html
> Sent from the Struts - User mailing list archive at Nabble.com.
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
> For additional commands, e-mail: user-help@struts.apache.org
>
>



-- 
"Hey you! Would you help me to carry the stone?" Pink Floyd

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


Re: how do you test your action classes?

Posted by phillips1021 <bp...@ku.edu>.
Musachy:

  I'm using the code for the JUnit plugin (2.1.8) to do testing of Struts 2
Actions.  My project is using the Spring and convention plugins.  The tests
execute successfully, but a FileNotFoundException is thrown.  Here is the
relevant log data when running the test.

2009-09-17 10:44:13,377 WARN 
org.springframework.mock.web.MockServletContext.getResourcePaths:212 -
Couldn't get resource paths for class path resource [WEB-INF/content/]
java.io.FileNotFoundException: class path resource [WEB-INF/content/] cannot
be resolved to URL because it does not exist
	at
org.springframework.core.io.ClassPathResource.getURL(ClassPathResource.java:163)
	at
org.springframework.core.io.ClassPathResource.getFile(ClassPathResource.java:175)
	at
org.springframework.mock.web.MockServletContext.getResourcePaths(MockServletContext.java:196)
at
org.apache.struts2.convention.DefaultResultMapBuilder.createFromResources(DefaultResultMapBuilder.java:227)
	at
org.apache.struts2.convention.DefaultResultMapBuilder.build(DefaultResultMapBuilder.java:183)
	at
org.apache.struts2.convention.PackageBasedActionConfigBuilder.createActionConfig(PackageBasedActionConfigBuilder.java:680)
	at
org.apache.struts2.convention.PackageBasedActionConfigBuilder.buildConfiguration(PackageBasedActionConfigBuilder.java:479)
	at
org.apache.struts2.convention.PackageBasedActionConfigBuilder.buildActionConfigs(PackageBasedActionConfigBuilder.java:278)
	at
org.apache.struts2.convention.ClasspathPackageProvider.loadPackages(ClasspathPackageProvider.java:52)
	at
com.opensymphony.xwork2.config.impl.DefaultConfiguration.reloadContainer(DefaultConfiguration.java:200)
	at
com.opensymphony.xwork2.config.ConfigurationManager.getConfiguration(ConfigurationManager.java:55)
	at
org.apache.struts2.dispatcher.Dispatcher.init_PreloadConfiguration(Dispatcher.java:360)
	at org.apache.struts2.dispatcher.Dispatcher.init(Dispatcher.java:403)
	at
org.apache.struts2.util.StrutsTestCaseHelper.initDispatcher(StrutsTestCaseHelper.java:54)
	at
edu.ku.it.si.blackboarddemo.action.StrutsTestCase.initDispatcher(StrutsTestCase.java:207)
	at
edu.ku.it.si.blackboarddemo.action.StrutsTestCase.setUp(StrutsTestCase.java:193)

By default the convention plugin specifies that JSPs will be in
WEB-INF/content/.

I can send you a complete maven project with the test that demonstrates this
issue.

I'm using Spring plugin and convention plugin versions 2.1.6.

Bruce

Musachy Barroso wrote:
> 
> JUnit plugin has been around as long as I can remember. What is new in
> 2.1.8 is the ability to execute actions inside Struts and outside a
> container.
> 
> musachy
> 
> On Sat, Sep 5, 2009 at 7:58 AM, phillips1021<bp...@ku.edu> wrote:
>>
>> Since Musachy mentioned that the code wasn't yet released I wasn't sure
>> about
>> the protocol.
>>
>> I'll take your comment as yes its OK.
>>
>> Will the Struts 2 JUnit plugin jar be part of the 2.1.8 release?  I'd
>> like
>> to include in my article if people can expect it in 2.1.8 and be able to
>> just add a dependency in the pom.xml or include the downloaded jar in
>> their
>> classpath.  For now I understand they'll have to checkout the latest code
>> from subversion repository.
>>
>>
>>
>> newton.dave wrote:
>>>
>>> phillips1021 wrote:
>>>> is it OK if I write up a blog article with code example that shows
>>>> how to use the StrutsTestCase right now for writing unit tests?
>>>
>>> Why wouldn't it be?
>>>
>>> Dave
>>>
>>>
>>> ---------------------------------------------------------------------
>>> To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
>>> For additional commands, e-mail: user-help@struts.apache.org
>>>
>>>
>>>
>>
>> --
>> View this message in context:
>> http://www.nabble.com/how-do-you-test-your-action-classes--tp25289507p25309276.html
>> Sent from the Struts - User mailing list archive at Nabble.com.
>>
>>
>> ---------------------------------------------------------------------
>> To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
>> For additional commands, e-mail: user-help@struts.apache.org
>>
>>
> 
> 
> 
> -- 
> "Hey you! Would you help me to carry the stone?" Pink Floyd
> 
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
> For additional commands, e-mail: user-help@struts.apache.org
> 
> 
> 

-- 
View this message in context: http://www.nabble.com/how-do-you-test-your-action-classes--tp25289507p25491968.html
Sent from the Struts - User mailing list archive at Nabble.com.


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


Re: how do you test your action classes?

Posted by phillips1021 <bp...@ku.edu>.
Thanks again for the information.

I wrote up a blog article that discusses how I used the new version of the
JUnit Plugin and also includes a code example readers can download.

See:   http://tinyurl.com/n3hm42 http://tinyurl.com/n3hm42 

Bruce


Musachy Barroso wrote:
> 
> JUnit plugin has been around as long as I can remember. What is new in
> 2.1.8 is the ability to execute actions inside Struts and outside a
> container.
> 
> musachy
> 
-- 
View this message in context: http://www.nabble.com/how-do-you-test-your-action-classes--tp25289507p25312071.html
Sent from the Struts - User mailing list archive at Nabble.com.


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


Re: how do you test your action classes?

Posted by Musachy Barroso <mu...@gmail.com>.
JUnit plugin has been around as long as I can remember. What is new in
2.1.8 is the ability to execute actions inside Struts and outside a
container.

musachy

On Sat, Sep 5, 2009 at 7:58 AM, phillips1021<bp...@ku.edu> wrote:
>
> Since Musachy mentioned that the code wasn't yet released I wasn't sure about
> the protocol.
>
> I'll take your comment as yes its OK.
>
> Will the Struts 2 JUnit plugin jar be part of the 2.1.8 release?  I'd like
> to include in my article if people can expect it in 2.1.8 and be able to
> just add a dependency in the pom.xml or include the downloaded jar in their
> classpath.  For now I understand they'll have to checkout the latest code
> from subversion repository.
>
>
>
> newton.dave wrote:
>>
>> phillips1021 wrote:
>>> is it OK if I write up a blog article with code example that shows
>>> how to use the StrutsTestCase right now for writing unit tests?
>>
>> Why wouldn't it be?
>>
>> Dave
>>
>>
>> ---------------------------------------------------------------------
>> To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
>> For additional commands, e-mail: user-help@struts.apache.org
>>
>>
>>
>
> --
> View this message in context: http://www.nabble.com/how-do-you-test-your-action-classes--tp25289507p25309276.html
> Sent from the Struts - User mailing list archive at Nabble.com.
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
> For additional commands, e-mail: user-help@struts.apache.org
>
>



-- 
"Hey you! Would you help me to carry the stone?" Pink Floyd

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


Re: how do you test your action classes?

Posted by phillips1021 <bp...@ku.edu>.
Since Musachy mentioned that the code wasn't yet released I wasn't sure about
the protocol.  

I'll take your comment as yes its OK.

Will the Struts 2 JUnit plugin jar be part of the 2.1.8 release?  I'd like
to include in my article if people can expect it in 2.1.8 and be able to
just add a dependency in the pom.xml or include the downloaded jar in their
classpath.  For now I understand they'll have to checkout the latest code
from subversion repository.



newton.dave wrote:
> 
> phillips1021 wrote:
>> is it OK if I write up a blog article with code example that shows
>> how to use the StrutsTestCase right now for writing unit tests?
> 
> Why wouldn't it be?
> 
> Dave
> 
> 
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
> For additional commands, e-mail: user-help@struts.apache.org
> 
> 
> 

-- 
View this message in context: http://www.nabble.com/how-do-you-test-your-action-classes--tp25289507p25309276.html
Sent from the Struts - User mailing list archive at Nabble.com.


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


Re: how do you test your action classes?

Posted by Dave Newton <ne...@yahoo.com>.
phillips1021 wrote:
> is it OK if I write up a blog article with code example that shows
> how to use the StrutsTestCase right now for writing unit tests?

Why wouldn't it be?

Dave


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


Re: how do you test your action classes?

Posted by phillips1021 <bp...@ku.edu>.
Musachy:

   I checked out the code and got my test to work when extending the
StrutsTestCase class.  

   The StrutsTestCase class is very easy to use and worked well.  The Struts
2 JUnit plugin will be very useful.  Will this plugin be part of the 2.1.8
release?

   Also is it OK if I write up a blog article with code example that shows
how to use the StrutsTestCase right now for writing unit tests?

Bruce

Musachy Barroso wrote:
> 
> You need to checkout the code from svn, some of the things mentioned
> in that page have not been released yet.
> 
> musachy
> 
-- 
View this message in context: http://www.nabble.com/how-do-you-test-your-action-classes--tp25289507p25308665.html
Sent from the Struts - User mailing list archive at Nabble.com.


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


Re: how do you test your action classes?

Posted by Musachy Barroso <mu...@gmail.com>.
You need to checkout the code from svn, some of the things mentioned
in that page have not been released yet.

musachy

On Fri, Sep 4, 2009 at 10:24 AM, phillips1021<bp...@ku.edu> wrote:
>
> Musachy:
>
>   Is the JUnit code shown in the example on the Testing Actions wiki page
> missing some statements?  For example I'm getting request cannot be resolved
> when I copy all this code into my Java IDE.
>
>   Thanks for posting the information on the Struts 2 JUnit Plugin.  I had
> not heard of it before now.
>
> Bruce
>
> Musachy Barroso wrote:
>>
>> I added a FAQ for it:
>> http://cwiki.apache.org/confluence/pages/viewpage.action?pageId=2853342
>> it points to the  "Testing Actions" page. Feel free to edit that page
>> and add more stuff to it.
>>
>> musachy
>>
>>
> --
> View this message in context: http://www.nabble.com/how-do-you-test-your-action-classes--tp25289507p25298537.html
> Sent from the Struts - User mailing list archive at Nabble.com.
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
> For additional commands, e-mail: user-help@struts.apache.org
>
>



-- 
"Hey you! Would you help me to carry the stone?" Pink Floyd

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


Re: how do you test your action classes?

Posted by phillips1021 <bp...@ku.edu>.
Musachy:

   Is the JUnit code shown in the example on the Testing Actions wiki page
missing some statements?  For example I'm getting request cannot be resolved
when I copy all this code into my Java IDE.

   Thanks for posting the information on the Struts 2 JUnit Plugin.  I had
not heard of it before now.

Bruce

Musachy Barroso wrote:
> 
> I added a FAQ for it:
> http://cwiki.apache.org/confluence/pages/viewpage.action?pageId=2853342
> it points to the  "Testing Actions" page. Feel free to edit that page
> and add more stuff to it.
> 
> musachy
> 
> 
-- 
View this message in context: http://www.nabble.com/how-do-you-test-your-action-classes--tp25289507p25298537.html
Sent from the Struts - User mailing list archive at Nabble.com.


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


Re: how do you test your action classes?

Posted by Musachy Barroso <mu...@gmail.com>.
I added a FAQ for it:
http://cwiki.apache.org/confluence/pages/viewpage.action?pageId=2853342
it points to the  "Testing Actions" page. Feel free to edit that page
and add more stuff to it.

musachy

On Fri, Sep 4, 2009 at 6:19 AM, Greg Lindholm<gr...@gmail.com> wrote:
> You probably should sure the mail archives (on Nabble) as this question come
> up very often.
> In fact it should be in a FAQ but there is some disagreement as what
> constitutes appropriate testing and what methods should be used.
>
> I've written up this article [1] on how to unit test actions in the full
> Struts 2 context with the Interceptor stack and validations.
>
> Others, seem to think this is the wrong approach and this type of testing
> should be done with a tool like Selenium.  Here is the last big thread on
> testing methods [2].
>
> [1] http://glindholm.wordpress.com/2008/06/30/unit-testing-struts-2-actions/
>
> [2]
> http://www.nabble.com/unit-testing-Struts2-application-%28with-Spring-and-Hibernate%29-ts24517800.html
>
> On Fri, Sep 4, 2009 at 3:23 AM, Rusty Wright <ru...@gmail.com> wrote:
>
>> For example, how can I test the validations if I'm using an xml file with
>> the validation specifications in it?  Seems like there are a lot of moving
>> parts around the invocation of the action classes that make testing hard.
>>
>> ---------------------------------------------------------------------
>> To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
>> For additional commands, e-mail: user-help@struts.apache.org
>>
>>
>



-- 
"Hey you! Would you help me to carry the stone?" Pink Floyd

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


Re: how do you test your action classes?

Posted by Wes Wannemacher <we...@wantii.com>.
On Fri, Sep 4, 2009 at 9:19 AM, Greg Lindholm<gr...@gmail.com> wrote:
> You probably should sure the mail archives (on Nabble) as this question come
> up very often.
> In fact it should be in a FAQ but there is some disagreement as what
> constitutes appropriate testing and what methods should be used.
>
> I've written up this article [1] on how to unit test actions in the full
> Struts 2 context with the Interceptor stack and validations.
>
> Others, seem to think this is the wrong approach and this type of testing
> should be done with a tool like Selenium.  Here is the last big thread on
> testing methods [2].
>
> [1] http://glindholm.wordpress.com/2008/06/30/unit-testing-struts-2-actions/
>
> [2]
> http://www.nabble.com/unit-testing-Struts2-application-%28with-Spring-and-Hibernate%29-ts24517800.html
>
> On Fri, Sep 4, 2009 at 3:23 AM, Rusty Wright <ru...@gmail.com> wrote:
>
>> For example, how can I test the validations if I'm using an xml file with
>> the validation specifications in it?  Seems like there are a lot of moving
>> parts around the invocation of the action classes that make testing hard.
>>
>> ---------------------------------------------------------------------
>> To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
>> For additional commands, e-mail: user-help@struts.apache.org
>>
>>
>

Make sure and read through that nabble thread Greg linked to. When
it's all said and done, each project is different and each developer
will have a different notion of how unit testing should be done. Even
though it was a heated argument mostly between Greg and I, I can see
since that thread that people often want this type of functionality
and I'm the kind of guy that isn't going to try to waste cycles trying
to convince everyone... So if you like his approach, go for it. If you
are on the other side of the fence then take a look at selenium or
jwebunit... Either approach will skin the cat, it's up to you and the
other people on your project which method you choose.

-Wes

-- 
Wes Wannemacher

Head Engineer, WanTii, Inc.
Need Training? Struts, Spring, Maven, Tomcat...
Ask me for a quote!

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


Re: how do you test your action classes?

Posted by phillips1021 <bp...@ku.edu>.
Greg:

   I wish I had found your code earlier.    I made  a minor change as the
createActionProxy method signature your code used has been deprecated.  I
added your code and a test case that uses it to my example application (see:  
http://tinyurl.com/nw4jve http://tinyurl.com/nw4jve  ).  

   Thanks for the work you've done on unit testing Struts 2 Action classes.

Bruce

I've written up this article [1] on how to unit test actions in the full
Struts 2 context with the Interceptor stack and validations.

[1] http://glindholm.wordpress.com/2008/06/30/unit-testing-struts-2-actions/



-- 
View this message in context: http://www.nabble.com/how-do-you-test-your-action-classes--tp25289507p25297970.html
Sent from the Struts - User mailing list archive at Nabble.com.


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


Re: how do you test your action classes?

Posted by Greg Lindholm <gr...@gmail.com>.
You probably should sure the mail archives (on Nabble) as this question come
up very often.
In fact it should be in a FAQ but there is some disagreement as what
constitutes appropriate testing and what methods should be used.

I've written up this article [1] on how to unit test actions in the full
Struts 2 context with the Interceptor stack and validations.

Others, seem to think this is the wrong approach and this type of testing
should be done with a tool like Selenium.  Here is the last big thread on
testing methods [2].

[1] http://glindholm.wordpress.com/2008/06/30/unit-testing-struts-2-actions/

[2]
http://www.nabble.com/unit-testing-Struts2-application-%28with-Spring-and-Hibernate%29-ts24517800.html

On Fri, Sep 4, 2009 at 3:23 AM, Rusty Wright <ru...@gmail.com> wrote:

> For example, how can I test the validations if I'm using an xml file with
> the validation specifications in it?  Seems like there are a lot of moving
> parts around the invocation of the action classes that make testing hard.
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
> For additional commands, e-mail: user-help@struts.apache.org
>
>

Re: how do you test your action classes?

Posted by phillips1021 <bp...@ku.edu>.
Rusty:

I’m also researching how to best write unit tests for Struts 2 Action
classes.  

Unit testing the business logic, service classes, etc that are outside the
Struts 2 Action class is not the problem.  The problem is unit testing the
Action class that requires the Struts 2 framework and configuration (for
example relies upon the Struts 2 interceptors being fired).

I wrote up a blog article (http://tinyurl.com/nw4jve) on what I’m able to do
so far.  Based on some work done by others, I was able to create a unit test
for an Action class’s validate method.  I've not yet tried it with the
validation being specified in an XML file, so if you could test that option
and let me know that would be helpful.

The blog article cited by Greg didn't come up in my Google and Struts 2 user
mail list searches.  I'm going to study his code (which probably is much
better than my initial attempt).  

As far as the debate that Greg and Wes mention, I feel that having an easy
way to automate testing  your validation logic is one good reason for unit
tests.  It looks like the work done by Greg and others have made it easier
to write a unit test that will test a Struts 2 Action class within the
context of the framework and your application's Struts 2 configuration.






-- 
View this message in context: http://www.nabble.com/how-do-you-test-your-action-classes--tp25289507p25297219.html
Sent from the Struts - User mailing list archive at Nabble.com.


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