locked
nunit RRS feed

  • Question

  • User270870739 posted

    In my application, the business logic is written in the page_load function itself and it does not return anything(void). In the page load, web method is called and the object is displayed on the ASP page. In any of these scenarios, no return type methods are used. All the methods are void type only. So, I think its not possible to implement nunit in this scenario. Please suggest.




    Hi,

              I am implementing nunit in my project. I am not getting idea how to implement the nunit after studying the documentation on it. Most of my code is:


     private void Page_Load(object sender, System.EventArgs e)
            {
                logger.Info("Loading the AgentDetails page");
                this.InitialiseRequest();
                //this.Title = "Agent Details";
                this.SetHeaderTabs(HeaderTabs1,1);
                logger.Info("Webservice method 'getAgentDetails' is called from the Web References layer");
                WSLayer.AgentDetails agtDet = this.WebService.getAgentDetails(this.AgentCode);
                this.AgentName = agtDet.Subagent[0].Fullname;
                this.SetTitleBar(HeaderTitleBar1);
                this.SetAgentDetails(AgentDetails1);
                logger.Info("End of Loading the AgentDetails page");
                           
        }

    Could you please suggest me here? Can I write asserts inside this block itself?

    Monday, February 1, 2010 5:52 AM

All replies

  • User559104930 posted

    First, do not under any circumstances include unit test code in your UI or code-behind. That is not what unit tests are for. Unit tests are for testing specific behavior of a class. For example, this tests the result of adding two numbers together:


            [TestMethod]
            public void Add_1And2_Returns3()
            {
                //arrange
                Calculator calculator = new Calculator();
    
                //act
                int result = calculator.Add(1, 2);
    
                //assert
                Assert.AreEqual(3, result);
            }
    


    Unit testing is a very large subject about which entire books have been written. I would suggest picking up a copy of The Art of Unit Testing.


    Monday, February 1, 2010 10:51 AM
  • User-319574463 posted

    In order to unit test in such a scenario, you need to extend NUnit either by using WaTiN. Previously you could have used NUnitAsp but development of this has been suspended.

    Wednesday, February 3, 2010 7:52 AM