Do you know how to structure a unit test (aka the 3 a's)?
Updated by Brady Stroud [SSW] 1 year ago. See history
123
No component provided for introEmbed
In the "Arrange" step we get everything ready and make sure we have all things handy for the "Act" step.
The "Act" step executes the relevant code piece that we want to test.
The "Assert" step verifies our expectations by stating what we were expecting from the system under test.
Developers call this the "AAA" syntax.
[TestMethod]public void TestRegisterPost_ValidUser_ReturnsRedirect(){// ArrangeAccountController controller = GetAccountController();RegisterModel model = new RegisterModel(){UserName = "someUser",Email = "goodEmail",Password = "goodPassword",ConfirmPassword = "goodPassword"};// ActActionResult result = controller.Register(model);// AssertRedirectToRouteResult redirectResult = (RedirectToRouteResult)result;Assert.AreEqual("Home", redirectResult.RouteValues["controller"]);Assert.AreEqual("Index", redirectResult.RouteValues["action"]);}
✅ Figure: Figure: A good structure for a unit test
Categories
Related rules
Need help?
SSW Consulting has over 30 years of experience developing awesome software solutions.