I'm not typically looking for an answer to every question here but more links to learning resources and perhaps advice about some of my points
I'm trying to implement Unit Testing in a project of mine but I can't find any tutorials (ideally video tutorials) that go into enough detail.
A- 1. How do I separate the concerns enough to unit test my functionality individually?
A- 2. What should I focus most on testing and where I should draw the line?
A- 3. What should an individual Unit Test cover and at what point should I break it down into 2 unit tests?
So I'm using Code First I've built up a product model, controller and views:
//
// GET: /Product/Edit/5
public ActionResult Edit(int id = 0)
{
Product product = db.Products.Find(id);
if (product == null)
{
return HttpNotFound();
}
return View(product);
}
//
// POST: /Product/Edit/5
[HttpPost]
public ActionResult Edit(Product product)
{
if (ModelState.IsValid)
{
db.Entry(product).State = EntityState.Modified;
db.SaveChanges();
return RedirectToAction("Index");
}
return View(product);
}
[TestMethod]
public void TestEditView() {
// Arrange
ProductController controller = new ProductController();
// Act
ViewResult result = controller.Edit(2) as ViewResult;
// Assert
//make sure theres a result
Assert.IsNotNull(result);
//make sure it's the right results
Assert.AreEqual("Edit", result.ViewName);
//test a dropdownlist exists
Assert.IsNotNull(result.ViewBag.CategoryID);
}
B- 1. How should I test my POST method? Should I add in an extra layer for data management so I can write up unit tests to test that individually?
B- 2. Should I focus more on checking the view is returned or more on the data (for example: if I have a Edit.cshtml then it will always return (why test that?), the data returned is more important isn't it? or are my black boxes more important? or should I cover all 3?)
B- 3. Should I break down my Unit Test to test the view and data separately?
Again, there's a lot of questions but I think mainly I'm looking for examples, tutorials and ways to learn about how to use Unit Testing (and even MVC) as best as I can.