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

Re: how to test protected methods.

Expand Messages
  • Matthew Metlis
    I have to disagree. In the ideal world, we should test everything that is testable. Why would you *not* want to test a protected class? Matt Metlis
    Message 1 of 7 , Feb 28, 2005
    • 0 Attachment
      I have to disagree. In the ideal world, we should test everything
      that is testable. Why would you *not* want to test a protected class?

      Matt Metlis



      --- In junit@yahoogroups.com, Ty Paywa <tyronepaywa@y...> wrote:
      > If a protected class needs to be tested then maybe it
      > shouldn't be a protected class. Ask yourself why you
      > need to test a protected class.
      >
      > Ty
      >
      > --- Chris Dollin <kers@h...> wrote:
      >
      > > On Monday 28 February 2005 13:29, senthilnathan
      > > chinnasamy wrote:
      > > > hi members,
      > > > someone give me idea about how to test the
      > > protected methods
      > >
      > > (a) make them public.
      > >
      > > (b) hide the class behind an interface which doesn't
      > > include the
      > > protected methods. Make the protected methods
      > > public.
      > >
      > > (c) ensure the methods are package-visible (isn't
      > > that anyways
      > > the case for protected?). Put the test class in
      > > the same
      > > package.
      > >
      > > (d) (c), but keep the test classes elsewhere in the
      > > filesystem
      > > tree.
      > >
      > > (e) (c) or (d), except it's not the test classes
      > > that share the
      > > package, but a relay class.
      > >
      > > (f) Have the test classes define and use a subclass
      > > of the
      > > class with protected methods. In that test
      > > class, add
      > > public method(s) that delegate to the protected
      > > method(s).
      > >
      > > (g) Use reflection: look into a mirror and say "you
      > > don't need
      > > to use reflection. That would be a mistake."
      > >
      > > --
      > > Chris "electric hedgehog" Dollin
      > >
      > >
      >
      >
      >
      >
      >
      > __________________________________
      > Do you Yahoo!?
      > Yahoo! Mail - You care about security. So do we.
      > http://promotions.yahoo.com/new_mail
    • J. B. Rainsberger
      ... Ask yourself why you would ever need a protected class ever, ever, ever. -- J. B. (Joe) Rainsberger Diaspar Software Services
      Message 2 of 7 , Mar 1, 2005
      • 0 Attachment
        Ty Paywa wrote:
        > If a protected class needs to be tested then maybe it
        > shouldn't be a protected class. Ask yourself why you
        > need to test a protected class.

        Ask yourself why you would ever need a protected class ever, ever, ever.
        --
        J. B. (Joe) Rainsberger
        Diaspar Software Services
        http://www.diasparsoftware.com
        Author, JUnit Recipes: Practical Methods for Programmer Testing
      • Chip Dunning
        Maybe I misread Ty, but it sounds like he was implying that it was necessary to decide why you even needed a protected class - not that it should not be
        Message 3 of 7 , Mar 1, 2005
        • 0 Attachment
          Maybe I misread Ty, but it sounds like he was implying that it was
          necessary to decide why you even needed a protected class - not that
          it should not be tested. Just that it should probably not be
          protected.



          Chip


          On Mon, 28 Feb 2005 22:08:43 -0000, Matthew Metlis
          <matthew.metlis@...> wrote:
          >
          >
          > I have to disagree. In the ideal world, we should test everything
          > that is testable. Why would you *not* want to test a protected class?
          >
          > Matt Metlis
          >
          > --- In junit@yahoogroups.com, Ty Paywa <tyronepaywa@y...> wrote:
          > > If a protected class needs to be tested then maybe it
          > > shouldn't be a protected class. Ask yourself why you
          > > need to test a protected class.
          > >
          > > Ty
          > >
          > > --- Chris Dollin <kers@h...> wrote:
          > >
          > > > On Monday 28 February 2005 13:29, senthilnathan
          > > > chinnasamy wrote:
          > > > > hi members,
          > > > > someone give me idea about how to test the
          > > > protected methods
          > > >
          > > > (a) make them public.
          > > >
          > > > (b) hide the class behind an interface which doesn't
          > > > include the
          > > > protected methods. Make the protected methods
          > > > public.
          > > >
          > > > (c) ensure the methods are package-visible (isn't
          > > > that anyways
          > > > the case for protected?). Put the test class in
          > > > the same
          > > > package.
          > > >
          > > > (d) (c), but keep the test classes elsewhere in the
          > > > filesystem
          > > > tree.
          > > >
          > > > (e) (c) or (d), except it's not the test classes
          > > > that share the
          > > > package, but a relay class.
          > > >
          > > > (f) Have the test classes define and use a subclass
          > > > of the
          > > > class with protected methods. In that test
          > > > class, add
          > > > public method(s) that delegate to the protected
          > > > method(s).
          > > >
          > > > (g) Use reflection: look into a mirror and say "you
          > > > don't need
          > > > to use reflection. That would be a mistake."
          > > >
          > > > --
          > > > Chris "electric hedgehog" Dollin
          > > >
          > > >
          > >
          > >
          > >
          > >
          > >
          > > __________________________________
          > > Do you Yahoo!?
          > > Yahoo! Mail - You care about security. So do we.
          > > http://promotions.yahoo.com/new_mail
          >
          >
          > Yahoo! Groups Links
          >
          >
          >
          >
          >


          --
          "The reason the mainstream is considered a stream is because it's so
          shallow" --George Carlin
        • Sumukh
          It looks like this class MyClass has two tasks. It performs some operation on a list which is to be tested and I assume MyClass has other responsibilities
          Message 4 of 7 , Mar 1, 2005
          • 0 Attachment
            It looks like this class "MyClass" has two tasks. It performs some
            operation on a list which is to be tested and I assume "MyClass" has
            other responsibilities too. This is what I would do in this situation:
            * Create a wrapper class around the list which performs all the
            operations on the list(as the list has some logic based on which
            certain operations are performed on it, and you want to test that logic).
            * Make this wrapper class package protected as this is going to be
            used only in your "MyClass".
            * Write a test for your wrapper class and place your test class in the
            same package. All operations(methods) in there wrapper class will be
            public or package protected and there are no issues with preotected
            methods.

            Sumukh

            > Maybe I misread Ty, but it sounds like he was implying that it was
            > necessary to decide why you even needed a protected class - not that
            > it should not be tested. Just that it should probably not be
            > protected.
            >
            >
            >
            > Chip
            >
            >
            > On Mon, 28 Feb 2005 22:08:43 -0000, Matthew Metlis
            > <matthew.metlis@j...> wrote:
            > >
            > >
            > > I have to disagree. In the ideal world, we should test everything
            > > that is testable. Why would you *not* want to test a protected class?
            > >
            > > Matt Metlis
            > >
            > > --- In junit@yahoogroups.com, Ty Paywa <tyronepaywa@y...> wrote:
            > > > If a protected class needs to be tested then maybe it
            > > > shouldn't be a protected class. Ask yourself why you
            > > > need to test a protected class.
            > > >
            > > > Ty
            > > >
            > > > --- Chris Dollin <kers@h...> wrote:
            > > >
            > > > > On Monday 28 February 2005 13:29, senthilnathan
            > > > > chinnasamy wrote:
            > > > > > hi members,
            > > > > > someone give me idea about how to test the
            > > > > protected methods
            > > > >
            > > > > (a) make them public.
            > > > >
            > > > > (b) hide the class behind an interface which doesn't
            > > > > include the
            > > > > protected methods. Make the protected methods
            > > > > public.
            > > > >
            > > > > (c) ensure the methods are package-visible (isn't
            > > > > that anyways
            > > > > the case for protected?). Put the test class in
            > > > > the same
            > > > > package.
            > > > >
            > > > > (d) (c), but keep the test classes elsewhere in the
            > > > > filesystem
            > > > > tree.
            > > > >
            > > > > (e) (c) or (d), except it's not the test classes
            > > > > that share the
            > > > > package, but a relay class.
            > > > >
            > > > > (f) Have the test classes define and use a subclass
            > > > > of the
            > > > > class with protected methods. In that test
            > > > > class, add
            > > > > public method(s) that delegate to the protected
            > > > > method(s).
            > > > >
            > > > > (g) Use reflection: look into a mirror and say "you
            > > > > don't need
            > > > > to use reflection. That would be a mistake."
            > > > >
            > > > > --
            > > > > Chris "electric hedgehog" Dollin
            > > > >
            > > > >
            > > >
            > > >
            > > >
            > > >
            > > >
            > > > __________________________________
            > > > Do you Yahoo!?
            > > > Yahoo! Mail - You care about security. So do we.
            > > > http://promotions.yahoo.com/new_mail
            > >
            > >
            > > Yahoo! Groups Links
            > >
            > >
            > >
            > >
            > >
            >
            >
            > --
            > "The reason the mainstream is considered a stream is because it's so
            > shallow" --George Carlin
          Your message has been successfully submitted and would be delivered to recipients shortly.