I recently started writing on the asp.net mvc framework. I have a problem. I can not understand the meaning of unit tests. Let's look at an example
public class HomeController : Controller
{
public ActionResult Index()
{
ViewData["Message"] = "Welcome to ASP.NET MVC!";
return View();
}
public ActionResult About()
{
return View();
}
}
and tests
[TestMethod]
public void Index()
{
HomeController controller = new HomeController();
ViewResult result = controller.Index() as ViewResult;
ViewDataDictionary viewData = result.ViewData;
Assert.AreEqual("Welcome to ASP.NET MVC!", viewData["Message"]);
}
[TestMethod]
public void About()
{
HomeController controller = new HomeController();
ViewResult result = controller.About() as ViewResult;
Assert.IsNotNull(result);
}
I have some questions.
1) In which case, the About method will not return a View?
If there is no About representation, the method will return nothing. Obviously, just click "Run", enter the browser "Home / About" and see the result. Without any unit tests. This is faster than creating unit tests, running them ...
2) In which case, the About return diffrent ViewData method? Test yourself. It is faster than unit tests.
Look at checking account controller
Using this test, we can verify the success of registration. But it’s easier to launch the application and enter the login / password manually
. . ?
.