Quantcast

Grails services and tests: stupid QOD?

classic Classic list List threaded Threaded
7 messages Options
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate
star

Grails services and tests: stupid QOD?

Joe Little
Since switching to grails 2.0, I'm having trouble in creating tests
for new projects.

I have a service:

class DegreeUtilsService {

       
    String convertAcadTerm(Integer term) {
               
    /// snip
    }

and I have a test:

@TestFor(DegreeUtilsService)
class DegreeUtilsServiceTests {

    void testAcadTerm() {
        result = convertAcadTerm(1124)
                assert result == //commented out..
    }
       
}

I'm getting this error on testing:

groovy.lang.MissingMethodException: No signature of method:
edu.stanford.ee.degreemgmt.DegreeUtilsServiceTests.convertAcadTerm()
is
        at edu.stanford.ee.degreemgmt.DegreeUtilsServiceTests.testAcadTerm(DegreeUtilsServiceTests.groovy:15)

I think I'm missing something obvious. Originally, more 'def's were
used instead of the static types, but my head is hurting from hitting
the wall on this one.

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

    http://xircles.codehaus.org/manage_email


Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate
star

Re: Grails services and tests: stupid QOD?

Joe Little
Answering own question. Appears that @TestFor does a little less than
I thought, and I still had to define the method both static and
explicitly reference the method via the full package name. Sometimes I
think groovy does a little more than it does..


On Fri, Feb 3, 2012 at 5:23 PM, Joe Little <[hidden email]> wrote:

> Since switching to grails 2.0, I'm having trouble in creating tests
> for new projects.
>
> I have a service:
>
> class DegreeUtilsService {
>
>
>    String convertAcadTerm(Integer term) {
>
>    /// snip
>    }
>
> and I have a test:
>
> @TestFor(DegreeUtilsService)
> class DegreeUtilsServiceTests {
>
>    void testAcadTerm() {
>        result = convertAcadTerm(1124)
>                assert result == //commented out..
>    }
>
> }
>
> I'm getting this error on testing:
>
> groovy.lang.MissingMethodException: No signature of method:
> edu.stanford.ee.degreemgmt.DegreeUtilsServiceTests.convertAcadTerm()
> is
>        at edu.stanford.ee.degreemgmt.DegreeUtilsServiceTests.testAcadTerm(DegreeUtilsServiceTests.groovy:15)
>
> I think I'm missing something obvious. Originally, more 'def's were
> used instead of the static types, but my head is hurting from hitting
> the wall on this one.

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

    http://xircles.codehaus.org/manage_email


Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate
star

Re: Grails services and tests: stupid QOD?

Matthias Hryniszak
Well, you're wrong. The @TestFor annotation adds an instance of the class to your test. Therefore the following applies:

grails-app/services/DegreeUtilsService.groovy

class DegreeUtilsService {
  String convertAcadTerm(Integer input) {
    "!!${input}!!"
  }
}

test/unit/DegreeUtilsService.groovy

import org.junit.Test

@TestFor(DegreeUtilsService)
class DegreeUtilsServiceTest {
  @Test void testAcadTerm() {
    assert "!!123!!" == service.convertAcadTerm(123)
  }
}

Note the "service" instance here. That's what the @TestFor adds (among other things).

HTH.

Matthias.

2012/2/4 Joe Little <[hidden email]>
Answering own question. Appears that @TestFor does a little less than
I thought, and I still had to define the method both static and
explicitly reference the method via the full package name. Sometimes I
think groovy does a little more than it does..


On Fri, Feb 3, 2012 at 5:23 PM, Joe Little <[hidden email]> wrote:
> Since switching to grails 2.0, I'm having trouble in creating tests
> for new projects.
>
> I have a service:
>
> class DegreeUtilsService {
>
>
>    String convertAcadTerm(Integer term) {
>
>    /// snip
>    }
>
> and I have a test:
>
> @TestFor(DegreeUtilsService)
> class DegreeUtilsServiceTests {
>
>    void testAcadTerm() {
>        result = convertAcadTerm(1124)
>                assert result == //commented out..
>    }
>
> }
>
> I'm getting this error on testing:
>
> groovy.lang.MissingMethodException: No signature of method:
> edu.stanford.ee.degreemgmt.DegreeUtilsServiceTests.convertAcadTerm()
> is
>        at edu.stanford.ee.degreemgmt.DegreeUtilsServiceTests.testAcadTerm(DegreeUtilsServiceTests.groovy:15)
>
> I think I'm missing something obvious. Originally, more 'def's were
> used instead of the static types, but my head is hurting from hitting
> the wall on this one.

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

   http://xircles.codehaus.org/manage_email



Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate
star

Re: Grails services and tests: stupid QOD?

Joe Little
Wow. That sure did help. I don't see anywhere in the docs where you
use "service.*" for the methods, and can keep them instance types.
Where did you find this out?

On Sat, Feb 4, 2012 at 2:14 AM, Matthias Hryniszak <[hidden email]> wrote:

> Well, you're wrong. The @TestFor annotation adds an instance of the class to
> your test. Therefore the following applies:
>
> grails-app/services/DegreeUtilsService.groovy
>
> class DegreeUtilsService {
>   String convertAcadTerm(Integer input) {
>     "!!${input}!!"
>   }
> }
>
> test/unit/DegreeUtilsService.groovy
>
> import org.junit.Test
>
> @TestFor(DegreeUtilsService)
> class DegreeUtilsServiceTest {
>   @Test void testAcadTerm() {
>     assert "!!123!!" == service.convertAcadTerm(123)
>   }
> }
>
> Note the "service" instance here. That's what the @TestFor adds (among other
> things).
>
> HTH.
>
> Matthias.
>
> 2012/2/4 Joe Little <[hidden email]>
>>
>> Answering own question. Appears that @TestFor does a little less than
>> I thought, and I still had to define the method both static and
>> explicitly reference the method via the full package name. Sometimes I
>> think groovy does a little more than it does..
>>
>>
>> On Fri, Feb 3, 2012 at 5:23 PM, Joe Little <[hidden email]> wrote:
>> > Since switching to grails 2.0, I'm having trouble in creating tests
>> > for new projects.
>> >
>> > I have a service:
>> >
>> > class DegreeUtilsService {
>> >
>> >
>> >    String convertAcadTerm(Integer term) {
>> >
>> >    /// snip
>> >    }
>> >
>> > and I have a test:
>> >
>> > @TestFor(DegreeUtilsService)
>> > class DegreeUtilsServiceTests {
>> >
>> >    void testAcadTerm() {
>> >        result = convertAcadTerm(1124)
>> >                assert result == //commented out..
>> >    }
>> >
>> > }
>> >
>> > I'm getting this error on testing:
>> >
>> > groovy.lang.MissingMethodException: No signature of method:
>> > edu.stanford.ee.degreemgmt.DegreeUtilsServiceTests.convertAcadTerm()
>> > is
>> >        at
>> > edu.stanford.ee.degreemgmt.DegreeUtilsServiceTests.testAcadTerm(DegreeUtilsServiceTests.groovy:15)
>> >
>> > I think I'm missing something obvious. Originally, more 'def's were
>> > used instead of the static types, but my head is hurting from hitting
>> > the wall on this one.
>>
>> ---------------------------------------------------------------------
>> To unsubscribe from this list, please visit:
>>
>>    http://xircles.codehaus.org/manage_email
>>
>>
>

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

    http://xircles.codehaus.org/manage_email


Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate
star

Re: Grails services and tests: stupid QOD?

Matthias Hryniszak
It's the TestFor convention. If it's a Controller the variable is "controller" and if it is a Service the variable is "service".

Matthias

2012/2/4 Joe Little <[hidden email]>
Wow. That sure did help. I don't see anywhere in the docs where you
use "service.*" for the methods, and can keep them instance types.
Where did you find this out?

On Sat, Feb 4, 2012 at 2:14 AM, Matthias Hryniszak <[hidden email]> wrote:
> Well, you're wrong. The @TestFor annotation adds an instance of the class to
> your test. Therefore the following applies:
>
> grails-app/services/DegreeUtilsService.groovy
>
> class DegreeUtilsService {
>   String convertAcadTerm(Integer input) {
>     "!!${input}!!"
>   }
> }
>
> test/unit/DegreeUtilsService.groovy
>
> import org.junit.Test
>
> @TestFor(DegreeUtilsService)
> class DegreeUtilsServiceTest {
>   @Test void testAcadTerm() {
>     assert "!!123!!" == service.convertAcadTerm(123)
>   }
> }
>
> Note the "service" instance here. That's what the @TestFor adds (among other
> things).
>
> HTH.
>
> Matthias.
>
> 2012/2/4 Joe Little <[hidden email]>
>>
>> Answering own question. Appears that @TestFor does a little less than
>> I thought, and I still had to define the method both static and
>> explicitly reference the method via the full package name. Sometimes I
>> think groovy does a little more than it does..
>>
>>
>> On Fri, Feb 3, 2012 at 5:23 PM, Joe Little <[hidden email]> wrote:
>> > Since switching to grails 2.0, I'm having trouble in creating tests
>> > for new projects.
>> >
>> > I have a service:
>> >
>> > class DegreeUtilsService {
>> >
>> >
>> >    String convertAcadTerm(Integer term) {
>> >
>> >    /// snip
>> >    }
>> >
>> > and I have a test:
>> >
>> > @TestFor(DegreeUtilsService)
>> > class DegreeUtilsServiceTests {
>> >
>> >    void testAcadTerm() {
>> >        result = convertAcadTerm(1124)
>> >                assert result == //commented out..
>> >    }
>> >
>> > }
>> >
>> > I'm getting this error on testing:
>> >
>> > groovy.lang.MissingMethodException: No signature of method:
>> > edu.stanford.ee.degreemgmt.DegreeUtilsServiceTests.convertAcadTerm()
>> > is
>> >        at
>> > edu.stanford.ee.degreemgmt.DegreeUtilsServiceTests.testAcadTerm(DegreeUtilsServiceTests.groovy:15)
>> >
>> > I think I'm missing something obvious. Originally, more 'def's were
>> > used instead of the static types, but my head is hurting from hitting
>> > the wall on this one.
>>
>> ---------------------------------------------------------------------
>> To unsubscribe from this list, please visit:
>>
>>    http://xircles.codehaus.org/manage_email
>>
>>
>

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

   http://xircles.codehaus.org/manage_email



Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate
star

Re: Grails services and tests: stupid QOD?

Joe Little
Good to know, but is this documented anywhere for future generations? :)

On Sat, Feb 4, 2012 at 8:37 AM, Matthias Hryniszak <[hidden email]> wrote:

> It's the TestFor convention. If it's a Controller the variable is
> "controller" and if it is a Service the variable is "service".
>
> Matthias
>
> 2012/2/4 Joe Little <[hidden email]>
>>
>> Wow. That sure did help. I don't see anywhere in the docs where you
>> use "service.*" for the methods, and can keep them instance types.
>> Where did you find this out?
>>
>> On Sat, Feb 4, 2012 at 2:14 AM, Matthias Hryniszak <[hidden email]>
>> wrote:
>> > Well, you're wrong. The @TestFor annotation adds an instance of the
>> > class to
>> > your test. Therefore the following applies:
>> >
>> > grails-app/services/DegreeUtilsService.groovy
>> >
>> > class DegreeUtilsService {
>> >   String convertAcadTerm(Integer input) {
>> >     "!!${input}!!"
>> >   }
>> > }
>> >
>> > test/unit/DegreeUtilsService.groovy
>> >
>> > import org.junit.Test
>> >
>> > @TestFor(DegreeUtilsService)
>> > class DegreeUtilsServiceTest {
>> >   @Test void testAcadTerm() {
>> >     assert "!!123!!" == service.convertAcadTerm(123)
>> >   }
>> > }
>> >
>> > Note the "service" instance here. That's what the @TestFor adds (among
>> > other
>> > things).
>> >
>> > HTH.
>> >
>> > Matthias.
>> >
>> > 2012/2/4 Joe Little <[hidden email]>
>> >>
>> >> Answering own question. Appears that @TestFor does a little less than
>> >> I thought, and I still had to define the method both static and
>> >> explicitly reference the method via the full package name. Sometimes I
>> >> think groovy does a little more than it does..
>> >>
>> >>
>> >> On Fri, Feb 3, 2012 at 5:23 PM, Joe Little <[hidden email]> wrote:
>> >> > Since switching to grails 2.0, I'm having trouble in creating tests
>> >> > for new projects.
>> >> >
>> >> > I have a service:
>> >> >
>> >> > class DegreeUtilsService {
>> >> >
>> >> >
>> >> >    String convertAcadTerm(Integer term) {
>> >> >
>> >> >    /// snip
>> >> >    }
>> >> >
>> >> > and I have a test:
>> >> >
>> >> > @TestFor(DegreeUtilsService)
>> >> > class DegreeUtilsServiceTests {
>> >> >
>> >> >    void testAcadTerm() {
>> >> >        result = convertAcadTerm(1124)
>> >> >                assert result == //commented out..
>> >> >    }
>> >> >
>> >> > }
>> >> >
>> >> > I'm getting this error on testing:
>> >> >
>> >> > groovy.lang.MissingMethodException: No signature of method:
>> >> > edu.stanford.ee.degreemgmt.DegreeUtilsServiceTests.convertAcadTerm()
>> >> > is
>> >> >        at
>> >> >
>> >> > edu.stanford.ee.degreemgmt.DegreeUtilsServiceTests.testAcadTerm(DegreeUtilsServiceTests.groovy:15)
>> >> >
>> >> > I think I'm missing something obvious. Originally, more 'def's were
>> >> > used instead of the static types, but my head is hurting from hitting
>> >> > the wall on this one.
>> >>
>> >> ---------------------------------------------------------------------
>> >> To unsubscribe from this list, please visit:
>> >>
>> >>    http://xircles.codehaus.org/manage_email
>> >>
>> >>
>> >
>>
>> ---------------------------------------------------------------------
>> To unsubscribe from this list, please visit:
>>
>>    http://xircles.codehaus.org/manage_email
>>
>>
>

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

    http://xircles.codehaus.org/manage_email


Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate
star

Re: Grails services and tests: stupid QOD?

Matthias Hryniszak
I have no idea :) I just followed a gut feeling that I've developed over the years when working with Grails - and it usually works :)

But yes, you're right to ask this - maybe a Jira ticket to update the docs?

Matthias

2012/2/4 Joe Little <[hidden email]>
Good to know, but is this documented anywhere for future generations? :)

On Sat, Feb 4, 2012 at 8:37 AM, Matthias Hryniszak <[hidden email]> wrote:
> It's the TestFor convention. If it's a Controller the variable is
> "controller" and if it is a Service the variable is "service".
>
> Matthias
>
> 2012/2/4 Joe Little <[hidden email]>
>>
>> Wow. That sure did help. I don't see anywhere in the docs where you
>> use "service.*" for the methods, and can keep them instance types.
>> Where did you find this out?
>>
>> On Sat, Feb 4, 2012 at 2:14 AM, Matthias Hryniszak <[hidden email]>
>> wrote:
>> > Well, you're wrong. The @TestFor annotation adds an instance of the
>> > class to
>> > your test. Therefore the following applies:
>> >
>> > grails-app/services/DegreeUtilsService.groovy
>> >
>> > class DegreeUtilsService {
>> >   String convertAcadTerm(Integer input) {
>> >     "!!${input}!!"
>> >   }
>> > }
>> >
>> > test/unit/DegreeUtilsService.groovy
>> >
>> > import org.junit.Test
>> >
>> > @TestFor(DegreeUtilsService)
>> > class DegreeUtilsServiceTest {
>> >   @Test void testAcadTerm() {
>> >     assert "!!123!!" == service.convertAcadTerm(123)
>> >   }
>> > }
>> >
>> > Note the "service" instance here. That's what the @TestFor adds (among
>> > other
>> > things).
>> >
>> > HTH.
>> >
>> > Matthias.
>> >
>> > 2012/2/4 Joe Little <[hidden email]>
>> >>
>> >> Answering own question. Appears that @TestFor does a little less than
>> >> I thought, and I still had to define the method both static and
>> >> explicitly reference the method via the full package name. Sometimes I
>> >> think groovy does a little more than it does..
>> >>
>> >>
>> >> On Fri, Feb 3, 2012 at 5:23 PM, Joe Little <[hidden email]> wrote:
>> >> > Since switching to grails 2.0, I'm having trouble in creating tests
>> >> > for new projects.
>> >> >
>> >> > I have a service:
>> >> >
>> >> > class DegreeUtilsService {
>> >> >
>> >> >
>> >> >    String convertAcadTerm(Integer term) {
>> >> >
>> >> >    /// snip
>> >> >    }
>> >> >
>> >> > and I have a test:
>> >> >
>> >> > @TestFor(DegreeUtilsService)
>> >> > class DegreeUtilsServiceTests {
>> >> >
>> >> >    void testAcadTerm() {
>> >> >        result = convertAcadTerm(1124)
>> >> >                assert result == //commented out..
>> >> >    }
>> >> >
>> >> > }
>> >> >
>> >> > I'm getting this error on testing:
>> >> >
>> >> > groovy.lang.MissingMethodException: No signature of method:
>> >> > edu.stanford.ee.degreemgmt.DegreeUtilsServiceTests.convertAcadTerm()
>> >> > is
>> >> >        at
>> >> >
>> >> > edu.stanford.ee.degreemgmt.DegreeUtilsServiceTests.testAcadTerm(DegreeUtilsServiceTests.groovy:15)
>> >> >
>> >> > I think I'm missing something obvious. Originally, more 'def's were
>> >> > used instead of the static types, but my head is hurting from hitting
>> >> > the wall on this one.
>> >>
>> >> ---------------------------------------------------------------------
>> >> To unsubscribe from this list, please visit:
>> >>
>> >>    http://xircles.codehaus.org/manage_email
>> >>
>> >>
>> >
>>
>> ---------------------------------------------------------------------
>> To unsubscribe from this list, please visit:
>>
>>    http://xircles.codehaus.org/manage_email
>>
>>
>

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

   http://xircles.codehaus.org/manage_email



Loading...