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

Re: [junit] pattern for testing code in a JAR that I don't have until after the test starts

Expand Messages
  • Nguyen Phuc Hai
    Hi Tood, I do not know any tools help we solve this issue in advance but in JUnit we have the solution. JUnit allows us change the approach of running testing
    Message 1 of 6 , Sep 30, 2007
      Hi Tood,
      I do not know any tools help we solve this issue in advance but in JUnit we have the solution. JUnit allows us change the approach of running testing (with JUnit 4 it supports annotation RunWith that allows you can change the runner of test). With the custom runner, you can load the remoting implementation by using URLClassLoader. Be sure that you use interface and appropriate code in test code for compiling and running test code.

      Regards,
      Hai
      http://www.haiphucnguyen.net/blog/

      "Bradley, Todd" <todd.bradley@...> wrote: Hi, we use JUnit to do some system testing (in addition to unit
      testing). And even though I've used JUnit every work day for the past 3
      years, I have a new problem I'm not sure how to approach.

      I need to write some tests of a Java API that we're going to deliver to
      our customer. And so my basic plan is to write some JUnit test cases
      that will interact with our product through this Java API, just as a
      customer would. But I don't want to have any of our product source code
      checked out to do this. Instead, I want my JUnit test case's setUp() to
      find the appropriate JAR file on a remote system, fetch it locally, and
      then start running tests against it. That way, whenever the JAR file on
      the remote system (our system-under-test) changes, I know I'll be
      testing the latest API code.

      I've got all the tools at hand to find and fetch the JAR file, but I'm
      not sure what my approach should be to load the JAR at runtime AFTER my
      test (and thus the JVM it's running in) has already started. Any advice
      for me?

      Todd.
      ----
      Todd Bradley - Polycom, Inc.
      ReadiVideo QA Lead





      ---------------------------------
      Looking for a deal? Find great prices on flights and hotels with Yahoo! FareChase.

      [Non-text portions of this message have been removed]
    • Bradley, Todd
      Yeah, I don t really want to get into classloader shenanigans too much, personally, if it means the low level Java interface. But has anyone (like the Apache
      Message 2 of 6 , Oct 1, 2007
        Yeah, I don't really want to get into classloader shenanigans too much,
        personally, if it means the low level Java interface. But has anyone
        (like the Apache Jakarta projects, for instance) put out any tools to
        make the shenanigans easier to cope with for a casual user?

        The only thing stopping me from fetching the JAR file from the ant
        script that kicks the tests off is that all the logic for finding the
        remote system and copying files from it already exists in Java code
        that's part of my test framework. So I'd rather do all this from inside
        my test case's superclass, if possible, so I don't have to duplicate
        code.

        Also, Hai, your suggestion of using JUnit4's RunWith is an interesting
        one. I haven't use these capabilities, so I'll read up on it.

        Thanks to both of you. Any other suggestions?


        Todd.




        ________________________________

        From: junit@yahoogroups.com [mailto:junit@yahoogroups.com] On
        Behalf Of James Abley
        Sent: Sunday, September 30, 2007 3:01 PM
        To: junit@yahoogroups.com
        Subject: Re: [junit] pattern for testing code in a JAR that I
        don't have until after the test starts



        On 28/09/2007, Bradley, Todd <todd.bradley@...
        <mailto:todd.bradley%40polycom.com> > wrote:
        >
        >
        >
        >
        >
        >
        > Hi, we use JUnit to do some system testing (in addition to
        unit
        > testing). And even though I've used JUnit every work day for
        the past 3
        > years, I have a new problem I'm not sure how to approach.
        >
        > I need to write some tests of a Java API that we're going to
        deliver to
        > our customer. And so my basic plan is to write some JUnit test
        cases
        > that will interact with our product through this Java API,
        just as a
        > customer would. But I don't want to have any of our product
        source code
        > checked out to do this. Instead, I want my JUnit test case's
        setUp() to
        > find the appropriate JAR file on a remote system, fetch it
        locally, and
        > then start running tests against it. That way, whenever the
        JAR file on
        > the remote system (our system-under-test) changes, I know I'll
        be
        > testing the latest API code.
        >
        > I've got all the tools at hand to find and fetch the JAR file,
        but I'm
        > not sure what my approach should be to load the JAR at runtime
        AFTER my
        > test (and thus the JVM it's running in) has already started.
        Any advice
        > for me?

        To do that implies some sort of classloader shenanigans, which
        isn't pretty.

        What is stopping you from getting the latest version of the JAR
        as
        part of the ANT script / automated build process that runs the
        tests,
        before the tests start running?

        Cheers,

        James

        >
        > Todd.
        > ----
        > Todd Bradley - Polycom, Inc.
        > ReadiVideo QA Lead
        >






        [Non-text portions of this message have been removed]
      • James Abley
        ... ANT tasks are very simple to write, and typically a lot simpler than classloaders. ... I was going to suggest that if you can t do it via ANT, since I
        Message 3 of 6 , Oct 2, 2007
          On 01/10/2007, Bradley, Todd <todd.bradley@...> wrote:
          >
          > Yeah, I don't really want to get into classloader shenanigans too much,
          > personally, if it means the low level Java interface. But has anyone
          > (like the Apache Jakarta projects, for instance) put out any tools to
          > make the shenanigans easier to cope with for a casual user?
          >
          > The only thing stopping me from fetching the JAR file from the ant
          > script that kicks the tests off is that all the logic for finding the
          > remote system and copying files from it already exists in Java code
          > that's part of my test framework. So I'd rather do all this from inside
          > my test case's superclass, if possible, so I don't have to duplicate
          > code.

          ANT tasks are very simple to write, and typically a lot simpler than
          classloaders.

          >
          > Also, Hai, your suggestion of using JUnit4's RunWith is an interesting
          > one. I haven't use these capabilities, so I'll read up on it.

          I was going to suggest that if you can't do it via ANT, since I think
          whether you use a custom Runner or use JUnit 3.8, you will be doing
          classloader work.

          I'm not aware of any existing Runner that will introduce a new
          classloader, but Google might know.

          Cheers,

          James
        • tryquestions
          A good resource site http://question2answer.googlepages.com thanks. ... the past 3 ... deliver to ... cases ... as a ... source code ... setUp() to ...
          Message 4 of 6 , Oct 8, 2007
            A good resource site

            http://question2answer.googlepages.com

            thanks.
            --- In junit@yahoogroups.com, "James Abley" <james.abley@...> wrote:
            >
            > On 28/09/2007, Bradley, Todd <todd.bradley@...> wrote:
            > >
            > >
            > >
            > >
            > >
            > >
            > > Hi, we use JUnit to do some system testing (in addition to unit
            > > testing). And even though I've used JUnit every work day for
            the past 3
            > > years, I have a new problem I'm not sure how to approach.
            > >
            > > I need to write some tests of a Java API that we're going to
            deliver to
            > > our customer. And so my basic plan is to write some JUnit test
            cases
            > > that will interact with our product through this Java API, just
            as a
            > > customer would. But I don't want to have any of our product
            source code
            > > checked out to do this. Instead, I want my JUnit test case's
            setUp() to
            > > find the appropriate JAR file on a remote system, fetch it
            locally, and
            > > then start running tests against it. That way, whenever the
            JAR file on
            > > the remote system (our system-under-test) changes, I know I'll
            be
            > > testing the latest API code.
            > >
            > > I've got all the tools at hand to find and fetch the JAR file,
            but I'm
            > > not sure what my approach should be to load the JAR at runtime
            AFTER my
            > > test (and thus the JVM it's running in) has already started.
            Any advice
            > > for me?
            >
            > To do that implies some sort of classloader shenanigans, which
            isn't pretty.
            >
            > What is stopping you from getting the latest version of the JAR as
            > part of the ANT script / automated build process that runs the
            tests,
            > before the tests start running?
            >
            > Cheers,
            >
            > James
            >
            > >
            > > Todd.
            > > ----
            > > Todd Bradley - Polycom, Inc.
            > > ReadiVideo QA Lead
            > >
            >
          Your message has been successfully submitted and would be delivered to recipients shortly.