4.1. Problem

There were many similarities in my tests that were being copied and pasted throughout — an egregious violation of the DRY principle. Here are some things that I started to notice as I wrote more tests:

  • My assert statements were very similar and repeated in many tests.

  • My controller instantiation was similar and repeated many times.

  • My mocks were also looking very similar and need to be centralized.

I also did a lot of unnecessary coding for controller actions that needed to be refactored and cleaned up. Most actions were taking several parameters instead of accepting a typed object. It's a lot cleaner to write:

public ActionResult Create(User user)

than

public ActionResult Create(string username, string email, string password,
                           string phone)

Get ASP.NET MVC 1.0 Test Driven Development: Problem - Design - Solution now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.