문제

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

도움이 되었습니까?

해결책

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 {
}
라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top