Hello
Recently I've started to write on asp.net mvc framework. I have a problem. I can't understand meaning of the unit tests. Let's see on example
public class HomeController : Controller
{
public ActionResult Index()
{
ViewData["Message"] = "Welcome to ASP.NET MVC!";
return View();
}
public ActionResult About()
{
return View();
}
}
and the 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 a questions.
1) In what case, method About won't return View?
If there is no view About, method will return nothing. It' obviously It is simple to click "Run", type in browser "Home/About" and see result. Without any unit tests. It's more faster than creating unit tests, running them...
2) In what case, method About return diffrent ViewData? Check yourself. It's faster than unit tests
Let's see Account controller's test
Using this test we can check log in success. But it's more simple to run the application and type login/password manually
Please describe advantages of unit tests. In unit tests we'll enter data manually. So why can't we type it manually? Разъясните пожалуйста в чём их плюс. Если всё равно все тестировочные данные набиваешь руками не проще ли самому всё проверить