0

I recently had a slip up where, during a demo, navigation to a view failed because the view still referenced a property that I had removed from the view model.

The application still has very little logic, except mapping between domain model and view model, and I would like to introduce unit tests now, and proceed with a more TDD oriented approach, but this case has me stumped? How can I write a unit test that mocks a view?

abatishchev
  • 98,240
  • 88
  • 296
  • 433
ProfK
  • 49,207
  • 121
  • 399
  • 775
  • 3
    Do you have `MvcBuildViews` element set to `True` in your MVC .proj file? This will compile the views as part of the build and *should* detect these kinds of problems – Russ Cam Feb 14 '12 at 14:54
  • The compiler should give you a warning if you reference a property that a class doesn't have. For example if you invoke `@model WebUI.Models.PersonModel` -> `

    @Model.SomeNonExistantProperty

    `, the compiler should warn you about this. Now if this manifest in a red squiggly but no build time compiler error, someone please tell me. :)
    – Only Bolivian Here Feb 14 '12 at 14:57
  • Thanks @Russ. It's worth that I also needed to modify my web.config to get this to work, as advised in the answer to [this question](http://stackoverflow.com/questions/2762256/mvcbuildviews-true-with-entity-framework-in-asp-net-mvc-2). – ProfK Feb 14 '12 at 16:37

1 Answers1

0

I've used WatiN in the past for just that, however it looks like it might not be maintained anymore. The last update update was back in April (10 months ago).

Matt Grande
  • 11,964
  • 6
  • 62
  • 89