Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. Web Development
  3. ASP.NET
  4. Nunit and unit testing of ASP.NET application [modified]

Nunit and unit testing of ASP.NET application [modified]

Scheduled Pinned Locked Moved ASP.NET
questioncsharpasp-netcomtesting
7 Posts 3 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • S Offline
    S Offline
    Sandeep Akhare
    wrote on last edited by
    #1

    Hi all, Need your suggestions How should i approach testing functions in a ASP.NET application. Its not integration testing but a unit testing(functions) But the problem is It is nearly impossible to isolate a function due to dependencies Many funcition are expecting other objects like Page Class context, Configuration settings many more complex objects like session context... etc now how can i test this methods using Nunit framework how should i initialized these objects ? should i use mock object concept ? is Nunit framework appropriate tool for writing the test cases ? Please suggest

    Thanks and Regards Sandeep If If you look at what you do not have in life, you don't have anything, If you look at what you have in life, you have everything... " Check My Blog

    modified on Tuesday, August 4, 2009 3:55 PM

    C N 2 Replies Last reply
    0
    • S Sandeep Akhare

      Hi all, Need your suggestions How should i approach testing functions in a ASP.NET application. Its not integration testing but a unit testing(functions) But the problem is It is nearly impossible to isolate a function due to dependencies Many funcition are expecting other objects like Page Class context, Configuration settings many more complex objects like session context... etc now how can i test this methods using Nunit framework how should i initialized these objects ? should i use mock object concept ? is Nunit framework appropriate tool for writing the test cases ? Please suggest

      Thanks and Regards Sandeep If If you look at what you do not have in life, you don't have anything, If you look at what you have in life, you have everything... " Check My Blog

      modified on Tuesday, August 4, 2009 3:55 PM

      C Offline
      C Offline
      Christian Graus
      wrote on last edited by
      #2

      If you write good code, then your business tasks will be isolated from UI, and can be tested.

      Christian Graus Driven to the arms of OSX by Vista. Read my blog to find out how I've worked around bugs in Microsoft tools and frameworks.

      S 1 Reply Last reply
      0
      • S Sandeep Akhare

        Hi all, Need your suggestions How should i approach testing functions in a ASP.NET application. Its not integration testing but a unit testing(functions) But the problem is It is nearly impossible to isolate a function due to dependencies Many funcition are expecting other objects like Page Class context, Configuration settings many more complex objects like session context... etc now how can i test this methods using Nunit framework how should i initialized these objects ? should i use mock object concept ? is Nunit framework appropriate tool for writing the test cases ? Please suggest

        Thanks and Regards Sandeep If If you look at what you do not have in life, you don't have anything, If you look at what you have in life, you have everything... " Check My Blog

        modified on Tuesday, August 4, 2009 3:55 PM

        N Offline
        N Offline
        N a v a n e e t h
        wrote on last edited by
        #3

        Sandeep Akhare wrote:

        now how can i test this methods using Nunit framework

        You need to isolate the dependencies. Separate the code into several projects and have a single project for all your ASPX files. Now you can write tests for the other projects. Other projects should not get a reference to System.Web.

        Sandeep Akhare wrote:

        how should i initialized these objects ? should i use mock object concept ?

        Probably yes. You need to create an interface which wraps HttpContext. Inject this interface as a dependency to your business classes. Read more about dependency injection[^]. In your test cases, you can mock this interface and set expectations. I suggest Rhino Mocks[^] for mocking. It is a wise idea to program to interfaces than implementations.

        Sandeep Akhare wrote:

        is Nunit framework appropriate tool for writing the test cases ?

        Yes. Its a great piece of work. :)

        Navaneeth How to use google | Ask smart questions

        S 1 Reply Last reply
        0
        • C Christian Graus

          If you write good code, then your business tasks will be isolated from UI, and can be tested.

          Christian Graus Driven to the arms of OSX by Vista. Read my blog to find out how I've worked around bugs in Microsoft tools and frameworks.

          S Offline
          S Offline
          Sandeep Akhare
          wrote on last edited by
          #4

          Thanks Chris for your reply Thats the problem UI layer is having business rules implemented making quite hard to test the application. We are going to rewrite the application using MVC architecture but before to that we need to write Nunit test cases for existing application.

          Thanks and Regards Sandeep If If you look at what you do not have in life, you don't have anything, If you look at what you have in life, you have everything... " Check My Blog

          1 Reply Last reply
          0
          • N N a v a n e e t h

            Sandeep Akhare wrote:

            now how can i test this methods using Nunit framework

            You need to isolate the dependencies. Separate the code into several projects and have a single project for all your ASPX files. Now you can write tests for the other projects. Other projects should not get a reference to System.Web.

            Sandeep Akhare wrote:

            how should i initialized these objects ? should i use mock object concept ?

            Probably yes. You need to create an interface which wraps HttpContext. Inject this interface as a dependency to your business classes. Read more about dependency injection[^]. In your test cases, you can mock this interface and set expectations. I suggest Rhino Mocks[^] for mocking. It is a wise idea to program to interfaces than implementations.

            Sandeep Akhare wrote:

            is Nunit framework appropriate tool for writing the test cases ?

            Yes. Its a great piece of work. :)

            Navaneeth How to use google | Ask smart questions

            S Offline
            S Offline
            Sandeep Akhare
            wrote on last edited by
            #5

            Hey Navaneeth Congrates for becoming MVP!

            N a v a n e e t h wrote:

            You need to isolate the dependencies. Separate the code into several projects and have a single project for all your ASPX files. Now you can write tests for the other projects. Other projects should not get a reference to System.Web.

            You mean to seperate the business layer from UI only for Testing purpose ? for other suggestions i need to look in to them. Thanks for reply

            Thanks and Regards Sandeep If If you look at what you do not have in life, you don't have anything, If you look at what you have in life, you have everything... " Check My Blog

            N 1 Reply Last reply
            0
            • S Sandeep Akhare

              Hey Navaneeth Congrates for becoming MVP!

              N a v a n e e t h wrote:

              You need to isolate the dependencies. Separate the code into several projects and have a single project for all your ASPX files. Now you can write tests for the other projects. Other projects should not get a reference to System.Web.

              You mean to seperate the business layer from UI only for Testing purpose ? for other suggestions i need to look in to them. Thanks for reply

              Thanks and Regards Sandeep If If you look at what you do not have in life, you don't have anything, If you look at what you have in life, you have everything... " Check My Blog

              N Offline
              N Offline
              N a v a n e e t h
              wrote on last edited by
              #6

              Thanks :)

              Sandeep Akhare wrote:

              You mean to seperate the business layer from UI only for Testing purpose ?

              Separating business logic from UI is good not only for testing but also for improved maintainability. If you have business logic tied close to UI, it will be hard to write automated test cases. So the first step in your case would be to re-factor code to support automated testing.

              Navaneeth How to use google | Ask smart questions

              S 1 Reply Last reply
              0
              • N N a v a n e e t h

                Thanks :)

                Sandeep Akhare wrote:

                You mean to seperate the business layer from UI only for Testing purpose ?

                Separating business logic from UI is good not only for testing but also for improved maintainability. If you have business logic tied close to UI, it will be hard to write automated test cases. So the first step in your case would be to re-factor code to support automated testing.

                Navaneeth How to use google | Ask smart questions

                S Offline
                S Offline
                Sandeep Akhare
                wrote on last edited by
                #7

                Hi Navneeth, We are planning to re-factor the application for next release. But for current application i have to write the test cases for such complex application. I read the links you have mentioned but still i am not able to conclude anything 1. Wraping of httpContext :- does it mean creating the app domain for your application ? 2. inserting the dependency object still i am not sure how i will insert it ? Problem is Page is derived from one base class which is derived from another base class nad interfaces There are many properties and objects some of these properties are readonly like sessionContext

                Thanks and Regards Sandeep If If you look at what you do not have in life, you don't have anything, If you look at what you have in life, you have everything... " Check My Blog

                1 Reply Last reply
                0
                Reply
                • Reply as topic
                Log in to reply
                • Oldest to Newest
                • Newest to Oldest
                • Most Votes


                • Login

                • Don't have an account? Register

                • Login or register to search.
                • First post
                  Last post
                0
                • Categories
                • Recent
                • Tags
                • Popular
                • World
                • Users
                • Groups