0

I'm having some trouble unit testing the model returned by DefaultModelBinder. I want to feed in a fake form collection and check the model that it returns to make sure model properties are being bound properly. In my research, I'm not turning up -any- resources on testing the DefaultModelBinder. Maybe I'm missing something. Maybe I shouldn't be testing this part of MVC? Your thoughts?

Byron Sommardahl
  • 12,743
  • 15
  • 74
  • 131
  • 1
    Test your code. DefaultModelBinder is entirely not your code, so there is no need to test. You should go out of an assumption that provided framework works correctly. This is sometimes not true, but we can't be paranoid. – LukLed Apr 25 '10 at 14:02

1 Answers1

1

Byron, I really think you shouldn't be testing this. You have to focus on your controller actions and the interactions they may have with other components, like services, etc. The default model binder has already been tested by the MS team (I hope so :P). Just assume your action parameters have correctly been populated with the form posted values by the default model binder and test the actions in your controllers with objects built by yourself. This is what I usually do and what I have seen everywhere.

Regards.

uvita
  • 4,124
  • 1
  • 27
  • 23
  • Changed question a bit. I guess I'm really trying to test the ModelBinder output. – Byron Sommardahl Apr 25 '10 at 13:59
  • @Byron Sommardahl: You are trying to test if your input is correct (because input defines output). Testing is not about checking if input is good, but if code producing the output is ok. If you can't change it, what to test? – LukLed Apr 25 '10 at 14:04