Wait, isn't MVC testable by design? Yes, most of it is testable, but as for the Views, you have to resort to integration tests (which isn't bad by itself, but sometimes is not enough).
In my recent project, I needed to write a test verifying that if a user is not authenticated, she should see a login form and a registration form. Speaking in terms of implementation, this means that Html.RenderPartial should be invoked with paths to my partial views containing these forms. Looks like a good task for TypeMock Isolator, but I prefer working with CThru. Here's the test code (forgive me for not following the strict rules, such as one assert per test, this is just for clarity):
<TestFixture(), RunOnWeb()> _
Public Class OwnersPage_NotLoggedIn
Public Sub ContainsLoginPartial()
Dim spy As New RenderPartialSpy
Dim session As New TestSession
The RenderPartialSpy class can be reused (this is why I prefer CThru), here's the code for it:
Public Class RenderPartialSpy
Public Overrides Function ShouldIntercept(
ByVal info As CThru.InterceptInfo) As Boolean
"RenderPartialExtensions") AndAlso info.MethodName = "RenderPartial"
Private _viewNames As New List(Of String)
Public ReadOnly Property ViewNames() As IList(Of String)
Public Overrides Sub MethodBehavior(ByVal e As CThru.DuringCallbackEventArgs)
Here I just set it to intercept all calls on the RenderPartialExtensions class with the method name "RenderPartial". When the call is intercepted, I save the value of the second argument (remember this is an extension method) in my list. At the Assert stage, I'll be able to retrieve all saved values and check them.