Search code examples
javaunit-testingjunittestngintegration-testing

What is the standard practice of writing test cases in spring MVC application?


We are developing new Spring MVC application in which we have DAO and service layer. which layer should i write test cases in junit or testNG ?. What is the standard practice for this ?


Solution

  • Its always better to write cases in controller layer.
    If the test case execution happens in all the layer(from controller to DAO/DB) then the coverage will more(more than 90%). If you are using Mockito then you can mock the last layer(dao or any other layer), because sometimes DB operation are not suitable for test case.

    If you are fine with interact with DB then you will get better coverage than mocking DAO.

    NOTE: Try To cover most of the layer & functionality while writing test case.