service not injected in setUp method of integration test

classic Classic list List threaded Threaded
6 messages Options
gon
Reply | Threaded
Open this post in threaded view
|

service not injected in setUp method of integration test

gon
I have in grails 2.3

class MyServiceTest extends GroovyTestCase {
     def myService

     void setUp() {
         myService.doSomething() // myService here is null,
    }

    void testService() {
        myService.doSomething()
    }


when I run this integration test myService has not been injected yet when
the setUp method is running.

If I comment the setUp method DI works as expected.

Is this intended behavior ?

Thank You

Paolo

--
    Signature for Rent - Questo spazio si affitta
Paolo Piersanti  Software Developer & System Admininistrator



smime.p7s (5K) Download Attachment
gon
Reply | Threaded
Open this post in threaded view
|

Re: service not injected in setUp method of integration test

gon

No one on this ?

On 27/09/13 11:33, Paolo Piersanti wrote:

> I have in grails 2.3
>
> class MyServiceTest extends GroovyTestCase {
>     def myService
>
>     void setUp() {
>         myService.doSomething() // myService here is null,
>    }
>
>    void testService() {
>        myService.doSomething()
>    }
>
>
> when I run this integration test myService has not been injected yet when
> the setUp method is running.
>
> If I comment the setUp method DI works as expected.
>
> Is this intended behavior ?
>
> Thank You
>
> Paolo
>

--
    Signature for Rent - Questo spazio si affitta
Paolo Piersanti  Software Developer & System Admininistrator



smime.p7s (5K) Download Attachment
Reply | Threaded
Open this post in threaded view
|

Re: service not injected in setUp method of integration test

alxndrsn
I've not used JUnit for integration tests, but perhaps you need to
call `super.setUp()` at the top of your `setUp()` method?

On 1 October 2013 11:45, Paolo Piersanti <[hidden email]> wrote:

>
> No one on this ?
>
>
> On 27/09/13 11:33, Paolo Piersanti wrote:
>>
>> I have in grails 2.3
>>
>> class MyServiceTest extends GroovyTestCase {
>>     def myService
>>
>>     void setUp() {
>>         myService.doSomething() // myService here is null,
>>    }
>>
>>    void testService() {
>>        myService.doSomething()
>>    }
>>
>>
>> when I run this integration test myService has not been injected yet when
>> the setUp method is running.
>>
>> If I comment the setUp method DI works as expected.
>>
>> Is this intended behavior ?
>>
>> Thank You
>>
>> Paolo
>>
>
>
> --
>    Signature for Rent - Questo spazio si affitta
> Paolo Piersanti  Software Developer & System Admininistrator
>
>

---------------------------------------------------------------------
To unsubscribe from this list, please visit:

    http://xircles.codehaus.org/manage_email


gon
Reply | Threaded
Open this post in threaded view
|

Re: service not injected in setUp method of integration test

gon
On 01/10/13 11:04, Alex Anderson wrote:
> I've not used JUnit for integration tests, but perhaps you need to
> call `super.setUp()` at the top of your `setUp()` method?

No, It does not work.
What appears to me is that Dependency Injection has not yet been run
when the  junit' s setUp method is called.
It looks like a bug to me.

Paolo


--
    Signature for Rent - Questo spazio si affitta
Paolo Piersanti  Software Developer & System Admininistrator



smime.p7s (5K) Download Attachment
Reply | Threaded
Open this post in threaded view
|

Re: service not injected in setUp method of integration test

Roberto Guerra
I've always instantiated the service I'm testing in an integration test.

On 02-Oct-2013, at 8:26 AM, Paolo Piersanti <[hidden email]> wrote:

> On 01/10/13 11:04, Alex Anderson wrote:
>> I've not used JUnit for integration tests, but perhaps you need to
>> call `super.setUp()` at the top of your `setUp()` method?
>
> No, It does not work.
> What appears to me is that Dependency Injection has not yet been run
> when the  junit' s setUp method is called.
> It looks like a bug to me.
>
> Paolo
>
>
> --
>   Signature for Rent - Questo spazio si affitta
> Paolo Piersanti  Software Developer & System Admininistrator
>
>


---------------------------------------------------------------------
To unsubscribe from this list, please visit:

    http://xircles.codehaus.org/manage_email


gon
Reply | Threaded
Open this post in threaded view
|

Re: service not injected in setUp method of integration test

gon
On 02/10/13 16:42, Roberto Guerra wrote:
> I've always instantiated the service I'm testing in an integration test.
ok, but if your service has other dependencies then you are forced to
wire in
all of them yourself.
in integration tests services get injected as expected, not yet when the
junit setUp is running

I opened an issue GRAILS-10584 <http://jira.grails.org/browse/GRAILS-10584>

Paolo

--
    Signature for Rent - Questo spazio si affitta
Paolo Piersanti  Software Developer & System Admininistrator



smime.p7s (5K) Download Attachment