Question

I'm working on unit tests for a grails application. I've been successful at testing services and domains but stuck trying to test classes in the src/groovy folder. What do I have to do to access the saveCreateAndCall method?

@Artefact("Controller")
@Transactional(readOnly = true)
class BaseController<T> extends RestfulController<T> {

    protected def saveCreateAndCall(Object instance, boolean flush = false, Closure c) {
        if (instance.save(flush: flush)) {
            c.call instance
        } else {
            errorCreateResponse(instance)
        }
    }

any advice or feedback would be appreciated, thanks

Was it helpful?

Solution

You can create your BaseController as an abstract class and let it in the controllers folder.

abstract class BaseController<T> {
}

Normally I tend to create an concrete controller to test my base abstraction and use the @TestFor to use the Grails testing features for controllers.

Or you can annotate your test:

@GrailsUnitTestMixin
@Mock(MyDomainClass) 
class BaseControllerTest extends Specification {
}
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top