Mocking thymeleaf

classic Classic list List threaded Threaded
2 messages Options
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Mocking thymeleaf

dhrubo
Hi,
   I want to test my Spring MVC controller only. So i am using the Spring test framework with Spring boot. With @WebMvcTest I am able to load just that MVC specific slice. However this also loads my Thymeleaf view components. We do set the logical view name in our controller. But then its manipulated in an interceptor with layouts and things like that. But that interceptor seems not loaded so the correct/final view name is not loaded. As a result my tests fail, as it fails to load the right template.

Ideally, I just want to test the controller, hence view rendering should not happen. But it seems that is something I will not be able to change with Spring Test Dispatcher servlet. So is there anyway I can mock Thymeleaf view?

Thanks ... dhrubo
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: Mocking thymeleaf

dhrubo
I was able to move forward with my Thymeleaf templates in the test. I was able to mock the utility that manipulated the logical view name set in the ModelAndView object.

However I did not like the fact that for controller tests, the views are also rendered. Anyways this is a problem I believe with Spring test framework.

So to speed up my unit tests, I decided to use a blank Thymeleaf template as I did not want to verify the content of the generated view while doing controller unit tests.

Thanks ...dhrubo
Loading...