You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
When writing an Interceptor test, the first test does not actually call the before method in the interceptor at all even if you have a matchAll() in the constructor.
All subsequent tests after the first appear to work fine. It's only the first one that doesn't work. It seems that the bean isn't correctly registered in the application context and the call to: applicationContext.getBeansOfType(Interceptor).values() as Interceptor[] in the mockInterceptor method of InterceptorUnitTest returns an empty list.
I am somewhat surprised because this is pretty subtle and still present (Grails 4.0.1) and has taken me one full day of trials to understand why even the most simple test wouldn't call the interceptor before() logic.
A workaround is to "fake" an initial "loading" test which calls the infamous withInterceptors() method to load the needed interceptor(s).
When writing an Interceptor test, the first test does not actually call the before method in the interceptor at all even if you have a matchAll() in the constructor.
All subsequent tests after the first appear to work fine. It's only the first one that doesn't work. It seems that the bean isn't correctly registered in the application context and the call to:
applicationContext.getBeansOfType(Interceptor).values() as Interceptor[]
in the mockInterceptor method of InterceptorUnitTest returns an empty list.I've attached a test project showing the behavior.
InterceptorTestBug.zip
The text was updated successfully, but these errors were encountered: