Quantcast

mockTagLib failing unless test run in isolation

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

mockTagLib failing unless test run in isolation

brynblackcap
Hi all,

I have a unit test for a controller which makes a call to a custom taglib. In my unit test I am using the GroovyPageUnitTestMixin and then calling mockTagLib to make the custom taglib available to the controller method when it is called.

So my controller unit test looks like:

@Mixin(GroovyPageUnitTestMixin)
@TestFor(MyController)
@Mock([MyDomain])
class MyControllerTests {
...
    void myTestMethod(){
        mockTagLib(com.mypackage.MyTagLib)
        ...
        // create various mock domains
        ...
        controller.show()

        // bunch of assertions
    }
}

and this works perfectly when I run this test in isolation. However when I come to run all my tests together, ie calling:

grails test-app -coverage

this unit test fails on the call to mockTagLib() with the following message (class & package names changed, obviously):

groovy.lang.MissingMethodException: No signature of method: com.mypackage.MyControllerTests.mockTagLib() is applicable for argument types: (java.lang.Class) values: [class com.mypackage.MyTagLib]
Possible solutions: mockDomain(java.lang.Class)

Even the presence of just one other controller test class seems to prevent this one from running correctly and I am baffled as to why.

Being reasonably new to Grails unit testing, I dont really know where to start with this one - can anyone suggest why the GroovyPageUnitTestMixin would fail to inject the mockTagLib method into my unit test class when run in conjunction with other tests? Is there something that I should be clearing down in other tests which I am failing to do?

Grails version is v2.0.1

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

Re: mockTagLib failing unless test run in isolation

Miles Burton-2
I've seen a similar issue where Mixins are nuked under certain test scenarios (usually related to Junit). I'll be keen to hear what others have seen.

On Wed, Jul 11, 2012 at 10:04 AM, brynblackcap <[hidden email]> wrote:
Hi all,

I have a unit test for a controller which makes a call to a custom taglib.
In my unit test I am using the GroovyPageUnitTestMixin and then calling
mockTagLib to make the custom taglib available to the controller method when
it is called.

So my controller unit test looks like:

@Mixin(GroovyPageUnitTestMixin)
@TestFor(MyController)
@Mock([MyDomain])
class MyControllerTests {
...
    void myTestMethod(){
        mockTagLib(com.mypackage.MyTagLib)
        ...
        // create various mock domains
        ...
        controller.show()

        // bunch of assertions
    }
}

and this works perfectly when I run this test in isolation. However when I
come to run all my tests together, ie calling:

grails test-app -coverage

this unit test fails on the call to mockTagLib() with the following message
(class & package names changed, obviously):

groovy.lang.MissingMethodException: No signature of method:
com.mypackage.MyControllerTests.mockTagLib() is applicable for argument
types: (java.lang.Class) values: [class com.mypackage.MyTagLib]
Possible solutions: mockDomain(java.lang.Class)

Even the presence of just one other controller test class seems to prevent
this one from running correctly and I am baffled as to why.

Being reasonably new to Grails unit testing, I dont really know where to
start with this one - can anyone suggest why the GroovyPageUnitTestMixin
would fail to inject the mockTagLib method into my unit test class when run
in conjunction with other tests? Is there something that I should be
clearing down in other tests which I am failing to do?

Grails version is v2.0.1

Cheers in advance
Bryn

--
View this message in context: http://grails.1312388.n4.nabble.com/mockTagLib-failing-unless-test-run-in-isolation-tp4631375.html
Sent from the Grails - user mailing list archive at Nabble.com.

---------------------------------------------------------------------
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: mockTagLib failing unless test run in isolation

brynblackcap
In reply to this post by brynblackcap
Ok so I managed to resolve this issue by removing the mixin annotation and the call to mockTagLib, and simply adding the taglib class to the list of classes in the @Mock annotation. so my original code above now becomes

@TestFor(MyController)
@Mock([MyDomain, MyTagLib])
class MyControllerTests {
...
    void myTestMethod(){
        ...
        // create various mock domains
        ...
        controller.show()

        // bunch of assertions
    }
}

Problem seems now to be solved. As to why it broke using the original method, I have  no idea.
Loading...