ASP.Net MVC is Easier to Test than Model-View-Presenter

David Hayden's experience leads him to believe that Model-View-Presenter Seems Easier to Test Than ASP.NET MVC.  He asks for some insight from the inter-web to help him see the light.  He uses the following example to highlight the simplicity of testing MVP:

[Test]
public void EmptyCustomerNameShouldCauseInvalidCustomerMessage()
{
MockRepository mocks = new MockRepository();

IAddCustomerView mockView = mocks.CreateMock<IAddCustomerView>();
AddCustomerPresenter presenter = new AddCustomerPresenter(mockView);

Expect.Call(mockView.CustomerName).Return(string.Empty);
Expect.Call(mockView.CustomerTitle).Return("Jester");
Expect.Call(mockView.PhoneNumber).Return("555-1212");
mockView.Message = "Invalid Customer...";

mocks.ReplayAll();
presenter.onAddCustomer();
mocks.VerifyAll();
}

Here is the same unit test using MVC:

[Test]
public void EmptyCustomerNameShouldCauseInvalidCustomerMessage()
{
CustomerController controller = new CustomerController();

controller.Add(string.Empty, "Jester", "555-1212");

Assert.IsTrue(controller.ViewData.Contains("message"));
Assert.AreEqual("Invalid Customer...", controller.ViewData["message"]);
}

I hope this helps contrast the two approaches.  I will leave it up to you to decide which is simpler.

posted @ Monday, December 17, 2007 8:50 AM


Print

Comments on this entry:

# David Hayden on Testing MVP vs. MVC

Left by at 12/17/2007 10:20 AM

David Hayden on Testing MVP vs. MVC

# re: ASP.Net MVC is Easier to Test than Model-View-Presenter

Left by Willie Tilton at 12/17/2007 12:54 PM
Gravatar

Just by looking at the amount of lines of code I can tell you which looks easier to me.

Your comment:



 (will not be displayed)


 
 
 
Please add 1 and 4 and type the answer here:
 

Live Comment Preview:

 
«July»
SunMonTueWedThuFriSat
293012345
6789101112
13141516171819
20212223242526
272829303112
3456789