Loading ...
Sorry, an error occurred while loading the content.

Testing JSP and servlets.

Expand Messages
  • Gregor Rayman
    Hi, perhaps this question has been answered alredy and I missed the answer. I am using JUnit to test my packages and I really love it. Unfortunaltely, I have
    Message 1 of 6 , Aug 1, 2000
    • 0 Attachment
      Hi, perhaps this question has been answered alredy and I missed the answer.

      I am using JUnit to test my packages and I really love it. Unfortunaltely,
      I have no idea how to test Java Server Pages or HTTP Servlets.

      Is there any framework for doing this? Some class that sends an HTTP-reuqest
      and then receives and chcecks the HTTP-response?

      --
      gR
    • glen_stampoultzis@ansett.com.au
      ... http://c2.com/cgi/wiki?HttpUnit _____________________________________________________________________ CAUTION - This message may contain privileged and
      Message 2 of 6 , Aug 1, 2000
      • 0 Attachment
        >Hi, perhaps this question has been answered alredy and I missed the answer.
        >
        >I am using JUnit to test my packages and I really love it. Unfortunaltely,
        >I have no idea how to test Java Server Pages or HTTP Servlets.
        >
        >Is there any framework for doing this? Some class that sends an HTTP-reuqest
        >and then receives and chcecks the HTTP-response?

        http://c2.com/cgi/wiki?HttpUnit




        _____________________________________________________________________
        CAUTION - This message may contain privileged and confidential
        information intended only for the use of the addressee named above.
        If you are not the intended recipient of this message you are hereby
        notified that any use, dissemination, distribution or reproduction
        of this message is prohibited. If you have received this message in
        error please notify Ansett Australia immediately. Any views expressed
        in this message are those of the individual sender and may not
        necessarily reflect the views of Ansett Australia.

        ABN Ansett Australia Ltd 37 004 209 410
        ABN Ansett International Ltd 72 060 622 460
        _____________________________________________________________________
      • Tim Diggins
        I m trying to get my head around UnitTests, so bear with me if I get it wrong. According to what i ve following in the main testing thread, it s important to
        Message 3 of 6 , Aug 2, 2000
        • 0 Attachment
          I'm trying to get my head around UnitTests, so bear with me if I get it
          wrong.

          According to what i've following in the main testing thread, it's important
          to keep the presentation layer (or whatever you call it) separate from the
          rest of the objects (this makes testing easier), and then test presentation
          separately (poss just with functional tests?).

          So if we apply that to JSP - that would mean - keep most of the
          functionality in separate classes (with straightforward JUnit tests) and
          then use the JSP page to be the presenation layer and simply make calls into
          the external classes. Thus UnitTesting would be minimised for the JSP page
          itself - or possibly not a UnitTest at all but a functional test.

          I'm probably missing something here - please let me know what.

          best

          Tim



          > -----Original Message-----
          > From: Gregor Rayman [mailto:grayman@...]
          > Sent: 01 August 2000 15:04
          > To: extremeprogramming@egroups.com
          > Subject: [XP] Testing JSP and servlets.
          >
          >
          > Hi, perhaps this question has been answered alredy and I missed
          > the answer.
          >
          > I am using JUnit to test my packages and I really love it. Unfortunaltely,
          > I have no idea how to test Java Server Pages or HTTP Servlets.
          >
          > Is there any framework for doing this? Some class that sends an
          > HTTP-reuqest
          > and then receives and chcecks the HTTP-response?
          >
          > --
          > gR
          >
          >
          >
          >
          > To Post a message, send it to: extremeprogramming@...
          >
          > To Unsubscribe, send a blank message to:
          > extremeprogramming-unsubscribe@...
          >
          > Ad-free courtesy of objectmentor.com
        • Gareth Reeves
          Yes, all of the bellow. The real issue is more along the lines of the fact that servlets run inside the context of a servlet engine. Ideally you don t want to
          Message 4 of 6 , Aug 3, 2000
          • 0 Attachment
            Yes, all of the bellow.

            The real issue is more along the lines of the fact that servlets run inside
            the context of a servlet engine. Ideally you don't want to test the servlet
            in the engine, that's too big of a chunk or unit. So, you take the servlet
            out of the servlet engine and test them in isolation. To do that you need to
            provide dummy or mock implementations of the JSDK interfaces that the
            servlet engine realizes.

            The motivation for the Mock objects paper originated from this very problem
            so that's probably a good place to start. I also have a servlet testing
            harness which is basically just a very generic implementation of the mock
            objects. With either of these you can test the servlet in isolation.

            JSP's should really only be used as the 'V' in MVC. That means that they
            only do presentation and don't need to be tested. If you feel like you need
            to test a JSP then you aren't doing it right. Javasoft have called this
            approach Model II.

            The more questions I see about testing servlets the more I think I should
            finish my 'Unit Testing Servlets' paper (c:

            Gareth

            > -----Original Message-----
            > From: Tim Diggins [mailto:subscribed@...]
            > Sent: Wednesday, August 02, 2000 4:37 PM
            > To: extremeprogramming@egroups.com
            > Subject: RE: [XP] Testing JSP and servlets.
            >
            >
            > I'm trying to get my head around UnitTests, so bear with me if I get it
            > wrong.
            >
            > According to what i've following in the main testing thread, it's
            > important
            > to keep the presentation layer (or whatever you call it) separate from the
            > rest of the objects (this makes testing easier), and then test
            > presentation
            > separately (poss just with functional tests?).
            >
            > So if we apply that to JSP - that would mean - keep most of the
            > functionality in separate classes (with straightforward JUnit tests) and
            > then use the JSP page to be the presenation layer and simply make
            > calls into
            > the external classes. Thus UnitTesting would be minimised for the JSP page
            > itself - or possibly not a UnitTest at all but a functional test.
            >
            > I'm probably missing something here - please let me know what.
            >
            > best
            >
            > Tim
            >
            >
            >
            > > -----Original Message-----
            > > From: Gregor Rayman [mailto:grayman@...]
            > > Sent: 01 August 2000 15:04
            > > To: extremeprogramming@egroups.com
            > > Subject: [XP] Testing JSP and servlets.
            > >
            > >
            > > Hi, perhaps this question has been answered alredy and I missed
            > > the answer.
            > >
            > > I am using JUnit to test my packages and I really love it.
            > Unfortunaltely,
            > > I have no idea how to test Java Server Pages or HTTP Servlets.
            > >
            > > Is there any framework for doing this? Some class that sends an
            > > HTTP-reuqest
            > > and then receives and chcecks the HTTP-response?
            > >
            > > --
            > > gR
            > >
            > >
            > >
            > >
            > > To Post a message, send it to: extremeprogramming@...
            > >
            > > To Unsubscribe, send a blank message to:
            > > extremeprogramming-unsubscribe@...
            > >
            > > Ad-free courtesy of objectmentor.com
            >
            >
            > To Post a message, send it to: extremeprogramming@...
            >
            > To Unsubscribe, send a blank message to:
            > extremeprogramming-unsubscribe@...
            >
            > Ad-free courtesy of objectmentor.com
            >
          • Chris Cottee
            I have not used JSP, we used webmacro(a template engine for html) for similar purposes. However here is what we have been doing to test servlets: Delegate as
            Message 5 of 6 , Aug 4, 2000
            • 0 Attachment
              I have not used JSP, we used webmacro(a template engine for html) for
              similar purposes. However here is what we have been doing to test
              servlets:

              Delegate as much functionality as possible to other objects and test
              them.
              Check that the right objects are put into the web macro 'context'
              (web macro allows you to do stuff like put $widget.Name in your html
              and if you put a widget in the context it will replace this with
              result of widget.getName() ).
              Use very little code in the html (basically try to adhere to the law
              of Demeter in the code, i.e. only get hold of things directly)
              Test using HttpUnit which you can use to simulate forms being
              submitted and links being clicked on. This also means that webmacro
              processing errors are detected.

              We test fragments of JavaScript using the Rhino javaScript engine
              (from Netscape) which allows you to compile javaScript functions and
              then run them in your tests. We have only tested a couple of little
              functions and classes like this and we got stuck with our pages that
              used ActiveX objects (the simplest thing at the start of the project)
              but we it was a great relief when we figured out a way to test the
              scripts at all.

              I haven't used the MockObjects idea extensively but I think it is the
              way to tackle many of these difficult to test areas.
              Hope this is helpful.

              Chris
            • Russell Gold
              ... The problem of course is that servlets don t run in isolation. You can certainly get interesting results by counterfeiting the environment, but if you
              Message 6 of 6 , Aug 7, 2000
              • 0 Attachment
                On Thu, 3 Aug 2000, "Gareth Reeves" <reevesy@...> wrote:
                >Yes, all of the bellow.
                >
                >The real issue is more along the lines of the fact that servlets run inside
                >the context of a servlet engine. Ideally you don't want to test the servlet
                >in the engine, that's too big of a chunk or unit. So, you take the servlet
                >out of the servlet engine and test them in isolation. To do that you need to
                >provide dummy or mock implementations of the JSDK interfaces that the
                >servlet engine realizes.
                >
                >The motivation for the Mock objects paper originated from this very problem
                >so that's probably a good place to start. I also have a servlet testing
                >harness which is basically just a very generic implementation of the mock
                >objects. With either of these you can test the servlet in isolation.

                The problem of course is that servlets don't run in isolation. You can
                certainly get interesting results by counterfeiting the environment, but if
                you don't take into consideration the potentially complex interaction with
                the container, you are not actually testing everything relevant. For
                example, if a servlet actually forwards to a JSP (using the MVC approach,
                how do you test that the forwarding is correct?)

                >JSP's should really only be used as the 'V' in MVC. That means that they
                >only do presentation and don't need to be tested. If you feel like you need
                >to test a JSP then you aren't doing it right. Javasoft have called this
                >approach Model II.

                I strongly disagree. Even a basic JSP that simply presents information
                passed to it in a JavaBean has interesting application (but not business)
                logic to test. While testing
                that the right text values are displayed in the right place is pretty
                straightforward, the use of pull-down menus, multi-select list boxes, radio
                buttons and the like to display the data appropriately and capture the
                user's request is just complex enough to warrant real testing. Besides,
                without testing, how do you ensure that the code continues to work? In an
                academic sense you might prefer to believe that views are trivial, but I
                seen few that were.

                >The more questions I see about testing servlets the more I think I should
                >finish my 'Unit Testing Servlets' paper (c:

                Or take a look at the HttpUnit cookbook at
                <http://httpunit.sourceforge.net/doc/Cookbook.html>
              Your message has been successfully submitted and would be delivered to recipients shortly.