Skip to Content
Apr 16, 2018 at 05:01 PM

How to write unit test for controllers


We are writing unit test for commerce webservices (OCC) controllers, for example CartsControllers, UsersController etc. Almost all the methods within these controllers return web service DTO i.e the ones that ends with *WsDTO. This object conversion is done by dataMapper which is part of spring web application context. The challenge we are facing is unit test or integration tests cannot access web application context and fetch the bean from there. 90% of commerce webservices (OCC) controller methods are not testable without this since they all return DTOs. Mocking dataMapper itself will not achieve anything since that will defeat the purpose of writing test.

Please help!!