In ASP., we can easily unit test model and controller controllers, but for
The testing of view views is not so easy and straightforward. Here is a way to use Razorgenerator to
Unit tests.
Nonsense not much to say directly. The main methods and steps are as follows:
1. Create an ASP. NET MVC project and the corresponding test project.
2. Add the package to NuGet in the Web project: Razorgenerator.msbuild.
3. NuGet Add package in test project: razorgenerator.testing; add Package NUnit
4. Modify the code you want to test in a Web project views\shared\error.cshtml
@model system.web.mvc.handleerrorinfo@{ viewbag.title = "Error";} <div id= "Content" >
5. Add test code to the Web test project
Using system;using system.linq;using system.web.mvc;using htmlagilitypack;using nunit.framework;using Razorgenerator.testing;namespace webapplication1.tests.views.shared{[testfixture] public class ErrorTest1 { [Test] public void TestMethod1 () {asserthtml<asp._views_shared_error_cshtml, Handleerrorin Fo> ("Content", @ "6, run the test, test pass.
Using Razorgenerator to Unit Test view views