We spent a lot of time writing controller tests and trying to figure out how to get the rendered HTML from Controller.Index() What we didn't understand at the time was that this is not really the way it is designed to be tested. We still learned a lot even though it was learning how NOT to do things.
Basically if you are going to be testing MVC don't try to test the rendered results of a controller action. You can test that the ViewResult has the correct Model and that the View exists by checking for an empty ViewResult.Name, but don't expect to test the rendered HTML. Brian made a good point when he said, "Our views should be stupid. If anything is going to be smart it needs to the be the business layer and the controller needs to know hot to access the business layer." Now that is not word for word, but it's how I heard it. I question if this would be true for heavy client side scripted apps.
Still having a lot of fun with this, so keep an eye out for our future postings.
No comments:
Post a Comment