Unit testing a Grails custom taglib based on built-in Grails taglib

Posted by dipess on Stack Overflow See other posts from Stack Overflow or by dipess
Published on 2012-12-03T17:12:51Z Indexed on 2012/12/04 5:04 UTC
Read the original article Hit count: 260

Filed under:
|

I've an app based on Grails 1.3.7. And I need to write a unit test for a custom taglib that is based on the built-in taglib, <g:select /> to be specific.

I checked out the solution on this previous SO post but the solution stated is not working in my case (some properties are not being prooperly mocked up).

The other solution that I found was this. Using this approach, I get most of the properties of FormTagLib mocked up except for the grailsApplication property that select requires. The actual error that I get is Cannot invoke method getArtefact() on null object.

How can I properly write the unit test in such a case?

Edit
Here are my test class and the full stacktrace. Line #45 on the stacktrace is the call to the g.select from my custom taglib. My custom taglib is something like

def clientSpecificQueues = {attrs->
    def queueList = taskService.getClientSpecificQueues(session.clientName)
    def queueLabel = "Some String"


    if (queueList.size() > 0){
        out << queueLabel
    else
        out << g.select(name:'queueId', from: queueList, optionKey: 'id', optionValue: 'name')



}

© Stack Overflow or respective owner

Related posts about unit-testing

Related posts about grails