samedi 17 septembre 2016

Best practice for controller testing in MVC

Talking about an MVC framework, as you need to test your controllers wich of the two would be the best solution to have a stable product, with a well defined business logic avoiding time waste?

Assumed that I'm declaring controllers as services, having control on the dependecy injection.

  1. Unit test controllers, mocking the most complex services them use.

  2. Test controllers with simple integration tests and unit test just the services.

My idea is that a Controller is a framework object, just an instrument and not related to my business logic and that test it with an unit test doesn't ensure to have tested the whole call bootstrap, so the best time saving approach is to test it with integration tests, keeping actions small and unit test the business logic inside the services it uses.

I want to hear other opinions expecially in the mantainment of big projects.

Aucun commentaire:

Enregistrer un commentaire