Raja
Raja

Reputation: 391

Best practices to test Asp.net MVC applications

Whats the best practice to test an Asp.net MVC application?

Upvotes: 3

Views: 1558

Answers (1)

Mike Scott
Mike Scott

Reputation: 12463

Choose your testing framework - I recommend xUnit.net.

Decouple your classes using interfaces and use constructor injection in your controllers to satisfy dependencies. In your tests, pass mocks to your controllers using a mocking framework - I recommend MoQ.

When running the web site rather than tests, either have default constructors on your controllers that call the other constructors and pass your real implementations of your interfaces; or use a Dependency Injection (DI) container to do it automatically - I recommend StructureMap.

Hope that helps.

Upvotes: 5

Related Questions