You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@struts.apache.org by Diego Manilla Suárez <di...@xeridia.com> on 2009/09/11 13:12:42 UTC

Testing with Spring + Struts 2 + TestNG

Hi. I've been struggling to have tests for my Struts 2 actions working.

I'm using Struts 2 actions created by Spring, by the means of the Struts 
2 Spring plugin.

Both Struts 2 and Spring provide their own base classes to create test 
units, and since Java doesn't allow multiple inheritance, I've tried to 
extend one of the classes and trying to replicate the functionality 
provided by the other, with no luck so far, I get all kinds of obscure 
errors, especially from the Struts 2 part.

I also want to use TestNG, not JUnit.

I was wondering if there is a base class anywhere to create unit tests 
for Struts 2 actions inside Spring.

Thanks in advance.


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


RE: Testing with Spring + Struts 2 + TestNG

Posted by Martin Gainty <mg...@hotmail.com>.
send me your code and spring config I could setup a surefire harness for you
if you already have a pom.xml send that also or I'll create a new pom.xml

Martin Gainty 
______________________________________________ 
Verzicht und Vertraulichkeitanmerkung/Note de déni et de confidentialité
 
Diese Nachricht ist vertraulich. Sollten Sie nicht der vorgesehene Empfaenger sein, so bitten wir hoeflich um eine Mitteilung. Jede unbefugte Weiterleitung oder Fertigung einer Kopie ist unzulaessig. Diese Nachricht dient lediglich dem Austausch von Informationen und entfaltet keine rechtliche Bindungswirkung. Aufgrund der leichten Manipulierbarkeit von E-Mails koennen wir keine Haftung fuer den Inhalt uebernehmen.
Ce message est confidentiel et peut être privilégié. Si vous n'êtes pas le destinataire prévu, nous te demandons avec bonté que pour satisfaire informez l'expéditeur. N'importe quelle diffusion non autorisée ou la copie de ceci est interdite. Ce message sert à l'information seulement et n'aura pas n'importe quel effet légalement obligatoire. Étant donné que les email peuvent facilement être sujets à la manipulation, nous ne pouvons accepter aucune responsabilité pour le contenu fourni.




> Date: Fri, 11 Sep 2009 13:19:36 +0200
> Subject: Re: Testing with Spring + Struts 2 + TestNG
> From: nilsga@gmail.com
> To: user@struts.apache.org
> 
> If it's unit testing you want to do, can't you just test your actions
> without involving Spring or anything else? I usually just create a
> unit test where I instantiate my action, set the aproriate
> dependencies, and then just call the appropriate execute method.
> 
> Nils-H
> 
> 2009/9/11 Diego Manilla Suárez <di...@xeridia.com>:
> > Hi. I've been struggling to have tests for my Struts 2 actions working.
> >
> > I'm using Struts 2 actions created by Spring, by the means of the Struts 2
> > Spring plugin.
> >
> > Both Struts 2 and Spring provide their own base classes to create test
> > units, and since Java doesn't allow multiple inheritance, I've tried to
> > extend one of the classes and trying to replicate the functionality provided
> > by the other, with no luck so far, I get all kinds of obscure errors,
> > especially from the Struts 2 part.
> >
> > I also want to use TestNG, not JUnit.
> >
> > I was wondering if there is a base class anywhere to create unit tests for
> > Struts 2 actions inside Spring.
> >
> > Thanks in advance.
> >
> >
> > ---------------------------------------------------------------------
> > 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
> 

_________________________________________________________________
Windows Live: Make it easier for your friends to see what you’re up to on Facebook.
http://windowslive.com/Campaign/SocialNetworking?ocid=PID23285::T:WLMTAGL:ON:WL:en-US:SI_SB_facebook:082009

Re: Testing with Spring + Struts 2 + TestNG

Posted by Wes Wannemacher <we...@wantii.com>.
Here is an example -

@RunWith(SpringJUnit4ClassRunner.class)
@ContextConfiguration(locations={"classpath*:applicationContext-test.xml"})
public class SomeActionTest {

        @Autowired @Qualifier("dao")
        private MyAction myAction;

        public void testOne() {
...


The difference between applicationContext-test.xml and
applicationContext.xml is typically database settings, etc. For
complicated things like actions directly manipulating the request
object, I'll just setup some spring mocks.

-Wes

On Fri, Sep 11, 2009 at 9:31 AM, Wes Wannemacher <we...@wantii.com> wrote:
> I'm pretty much with Nils here, except that I use later versions of
> JUnit that support the @RunWith annotation and there is a spring class
> that you can use so that you can specify an applicationContext.xml
> file. That way, I can create a spring config file with beans defined
> specifically for testing (connected to HSQLDB for instance) and then
> just set @Autowired annotation on the struts action so that it gets
> all the spring bean dependencies injected, then write the unit tests
> against it.
>
> -Wes
>
> On Fri, Sep 11, 2009 at 7:19 AM, Nils-Helge Garli Hegvik
> <ni...@gmail.com> wrote:
>> If it's unit testing you want to do, can't you just test your actions
>> without involving Spring or anything else? I usually just create a
>> unit test where I instantiate my action, set the aproriate
>> dependencies, and then just call the appropriate execute method.
>>
>> Nils-H
>>
>> 2009/9/11 Diego Manilla Suárez <di...@xeridia.com>:
>>> Hi. I've been struggling to have tests for my Struts 2 actions working.
>>>
>>> I'm using Struts 2 actions created by Spring, by the means of the Struts 2
>>> Spring plugin.
>>>
>>> Both Struts 2 and Spring provide their own base classes to create test
>>> units, and since Java doesn't allow multiple inheritance, I've tried to
>>> extend one of the classes and trying to replicate the functionality provided
>>> by the other, with no luck so far, I get all kinds of obscure errors,
>>> especially from the Struts 2 part.
>>>
>>> I also want to use TestNG, not JUnit.
>>>
>>> I was wondering if there is a base class anywhere to create unit tests for
>>> Struts 2 actions inside Spring.
>>>
>>> Thanks in advance.
>>>
>>>
>>> ---------------------------------------------------------------------
>>> 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
>>
>>
>
>
>
> --
> Wes Wannemacher
>
> Head Engineer, WanTii, Inc.
> Need Training? Struts, Spring, Maven, Tomcat...
> Ask me for a quote!
>



-- 
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: Testing with Spring + Struts 2 + TestNG

Posted by Wes Wannemacher <we...@wantii.com>.
I'm pretty much with Nils here, except that I use later versions of
JUnit that support the @RunWith annotation and there is a spring class
that you can use so that you can specify an applicationContext.xml
file. That way, I can create a spring config file with beans defined
specifically for testing (connected to HSQLDB for instance) and then
just set @Autowired annotation on the struts action so that it gets
all the spring bean dependencies injected, then write the unit tests
against it.

-Wes

On Fri, Sep 11, 2009 at 7:19 AM, Nils-Helge Garli Hegvik
<ni...@gmail.com> wrote:
> If it's unit testing you want to do, can't you just test your actions
> without involving Spring or anything else? I usually just create a
> unit test where I instantiate my action, set the aproriate
> dependencies, and then just call the appropriate execute method.
>
> Nils-H
>
> 2009/9/11 Diego Manilla Suárez <di...@xeridia.com>:
>> Hi. I've been struggling to have tests for my Struts 2 actions working.
>>
>> I'm using Struts 2 actions created by Spring, by the means of the Struts 2
>> Spring plugin.
>>
>> Both Struts 2 and Spring provide their own base classes to create test
>> units, and since Java doesn't allow multiple inheritance, I've tried to
>> extend one of the classes and trying to replicate the functionality provided
>> by the other, with no luck so far, I get all kinds of obscure errors,
>> especially from the Struts 2 part.
>>
>> I also want to use TestNG, not JUnit.
>>
>> I was wondering if there is a base class anywhere to create unit tests for
>> Struts 2 actions inside Spring.
>>
>> Thanks in advance.
>>
>>
>> ---------------------------------------------------------------------
>> 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
>
>



-- 
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: Testing with Spring + Struts 2 + TestNG

Posted by Nils-Helge Garli Hegvik <ni...@gmail.com>.
If it's unit testing you want to do, can't you just test your actions
without involving Spring or anything else? I usually just create a
unit test where I instantiate my action, set the aproriate
dependencies, and then just call the appropriate execute method.

Nils-H

2009/9/11 Diego Manilla Suárez <di...@xeridia.com>:
> Hi. I've been struggling to have tests for my Struts 2 actions working.
>
> I'm using Struts 2 actions created by Spring, by the means of the Struts 2
> Spring plugin.
>
> Both Struts 2 and Spring provide their own base classes to create test
> units, and since Java doesn't allow multiple inheritance, I've tried to
> extend one of the classes and trying to replicate the functionality provided
> by the other, with no luck so far, I get all kinds of obscure errors,
> especially from the Struts 2 part.
>
> I also want to use TestNG, not JUnit.
>
> I was wondering if there is a base class anywhere to create unit tests for
> Struts 2 actions inside Spring.
>
> Thanks in advance.
>
>
> ---------------------------------------------------------------------
> 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