0

When our codebase was still in Grails 2.1.4, this unit test for our interceptors worked with full coverage:

@Before
void setUp() {
   gmc = new GMockController()
   apiProducts = gmc.mock()

   api.products.returns(apiProducts).stub()

   controller.api = api
}

void testBeforeInterceptor() {
   // Arrange
   setUp()
   def ctrl = gmc.mock(controller)
   params.id = 1
   ctrl.actionName.returns('view')
   apiProducts.get(params.id)

   // Act
   gmc.play {
       controller.beforeInterceptor()
   }
}

After switching to Grails 2.2.2, it seems like this doesn't cover the test like it used to in 2.1.4. The error "Unexpected method call" is being called out since it won't go through the interceptors like it used to in 2.1.4.

Was there a change in how interceptors are tested?

I've searched around and it seems like no one has the answer for this. The documentation on testing interceptors are sparse. Any ideas?

Ace Subido
  • 86
  • 9

1 Answers1

0

Grails does not invoke interceptors or servlet filters when calling actions during integration testing. You should test interceptors and filters in isolation, using functional testing if necessary.

(Untested) I am not sure whether this is applicable here for GMock. But integration tests doc mentions otherwise.

dmahapatro
  • 49,365
  • 7
  • 88
  • 117