Most of the stackoverflow posts about ASP.NET MVC unit testing talk about a specific issue or specific thing to test such as testing HtmlHelpers. Others on the subject of best practices have surprisingly few answers. Available videos I have watched are completely useless in my opinion - and mind blowingly long (by the time you've watched 1.5 hours and not learned anything).
What I want to know from people who've actually been doing this is :
I'm not new to how to unit test - but I'm very new to actually doing it consistently. I'd really appreciate lessons learned from those who are experts in unit testing ASP.NET MVC.
I'm really looking for specific things you might only find out after having tried it - not jsut general advice like 'use interfaces' - although of course any suggestions are welcome.
Oh and lets say I've decided to use Microsoft's unit testing - just becasue its already there. I think all answers would apply to all testing frameworks though.
The Model-View-Controller (MVC) architectural pattern separates an application into three main components: the model, the view, and the controller.
ASP.NET Core API. In computer programming, unit testing is a software testing method by which individual units of source code are tested to determine whether they are fit for use.
To test an application, you need to add a Unit Test project to the ASP.Net solution. All tests can be made to run in Visual Studio. A test explorer will show the results of all of the tests.
I'd like to elaborate on testing controller actions:
ActionResult
. A redirect is different from a view.In short, verify anything from the ActionResult
that you will use.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With