locked
Unit Test and Project RRS feed

  • Question

  • User1886340122 posted

    Hi all, Right i have a little project and i have done no unit test at all,

    I know in the agile concept your meant to:

    • Write the test first which should fail
    • Improve the code so that the test passes
    • Then refactor it to acceptable standards
    I have made a new project within my solutuion called Test, then i have created a folder called controller,
    Which will contain all my controller tests. I have managed to successfully do my first unit test which passed.

     Unit Test

    [TestClass]
    public class HomeControllerTests
    {
    [TestMethod]
    public void Index()
    {

    HomeController controller = new HomeController();

    ViewResult result = controller.Index() as ViewResult;

    Assert.AreEqual("Welcome to ASP.NET MVC!", result.ViewBag.Message);

    }
    Project
      public class HomeController : Controller
        {
    public ActionResult Index()
    {
    ViewBag.Message = "Welcome to ASP.NET MVC!";

    return View();
    }

    Now i cant do the following unit test

     Project

          public ActionResult SetUp()
    {
    return RedirectToAction("Create", "Organisation", new { area = "Setup" });
    }

    Unit Test Project

    [TestMethod]
            public void SetUp()
    {

    HomeController controller = new HomeController(); }
     
    
    
    I cant finish off the unit test i do not know what should go there to test the link, any help would be great thanks
    Friday, January 27, 2012 4:02 AM

Answers

  • User332351063 posted

    I suggest you testing bussiness method by unit tests. You controller should use only bussiness layer or other services and shouldn'h have any logic in controller. So i fou write test to bussiness layer methods and all test are passing and you have sure that bussiness layer work fine you have automatically ensure that controller will be work. Of course, you wanna test you UI as you mentioned above that you wanna test clicking on link, but this kind of test is rather integrate or functional test so you should know with SELENIUM. This is framework to UI testing. You can write code using this framwerok or you can even clicking on page only and selenium will record test for you.

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Friday, January 27, 2012 4:33 AM