MVC Pattern – Is Unit Testing the Primary Objective?

mvc

Recently in an interview, one of the questions was 'Why do we use MVC?’
I just answered that it is much closer to how, many of the real world systems are! Explained the benefits it has when it comes to Maintainability, Scalability etc. But they were not convinced and finally told me that MVC is used mainly as it 'enables easy Unit Testing'.

While I know theirs is a valid point, I still doubt if it is the major reason because (i) even if I decide not to write Unit Testcases, MVC is a probable choice (ii) Many GUI systems where Unit Testcases are there does not follow MVC.

So the question is 'Is Unit Testing the primary objective of MVC Pattern?'

EDIT: I assume that they might be mentioning ease of Test Driven Development/writing NUnit Testcases. This is because we canwrite testcases for the Model (Provided the View is exactly reflecting Model's state changes)-please correct me if I am wrong.

Best Answer

The primary objective would be "separation of concerns", as the model, the view and the controller all have distinct responsibilities.

The author of the original Xerox PARC paper states that:

The essential purpose of MVC is to bridge the gap between the human user's mental model and the digital model that exists in the computer.

If unit-testing were the primary objective, one would be able to easily unit-test views. A look at the landscape of unit-testing projects/frameworks would reveal that it is quite contrary to the claim made. One would typically be using integration and functional tests to test the view.

Related Topic