views:

57

answers:

4

I want to understand exactly what unit test means.

From what I have understood so far it implies testing a model and all its public methods.

Is that correct?

And what about controllers? Does unit test means testing the controllers/views too?

Could someone enlighten me on this.

+1  A: 

Unit testing as a concept exists outside of MVC.

So yes, you want to unit test all of your code, not just the model.

bstpierre
+1  A: 

Basically, if it has business logic that is non-trivial then it should be unit tested.

As you test the controller, if you have already tested lower levels, then you can mock out the lower levels so that your test will go quicker, but, everything should have a test, all the public and protected methods, not just the public ones, IMO.

James Black
+1  A: 

Unit testing as the name suggest is testing a code unit.

Theoretically you can test all the code, but sometimes this is hard to do.

If a controller should output something to the view you can test that.

Sometimes you may want to create a mock object to make things easier. For example, you can mock a DAO or a HttpResponse.

Daniel Moura
+1  A: 

Usually your model is 'dumb' in that it doesn't contain any logic, just properties and state. So the unit tests are centered around testing your repository and services which interact and use the domain objects and (if you use them) summary model objects.

You can also test the controllers which call these services for complete coverage. It all depends on how much of the project you would like to see tested. Testing the views is slightly harder, for .NET web-based projects you can use frameworks like Selenium and Watin which integrate into unit testing frameworks.

Chris S