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

JUnitX and private methods

Expand Messages
  • Andreas Heilwagen
    ... I am convinced that production code should not be mixed with test code. So Eric is right about JUnitX, it does not fool the Security Manager. JUnitX uses a
    Message 1 of 1 , Oct 1, 2000
    • 0 Attachment
      "John D. Mitchell" wrote:
      >
      > >>>>> "Eric" == Eric Hodges <harmony2@...> writes:
      > > 1. I'm afraid of the cost of refactoring going up. I use private methods
      > > and variables for things that I don't want anything else to depend on.
      > > This makes refactoring easier and increases my confidence.
      >
      > > 2. I'm afraid of the cost of testing going up. Testing private methods
      > > requires all kinds of weirdness with fooling the security manager or
      > > putting test code into production code or breaking privacy. If there
      > > were a "test" visibility keyword, or a "test" adornment for code that can
      > > ignore privacy, then I'd test them.
      >
      > > Maybe JUnitX could remove #2, but #1 is a big deal.
      >
      > As noted previously in an ancestor of this thread, there is no need to
      > violate encapsulation or do anything tricks with e.g., the security manager
      > to test private methods in Java. Write your white-box tests inside of a
      > nested public static class.
      >
      > In terms of your concern about extraneous coupling, using a nested class is
      > awfully clean and the source is right there as part of your primary class.

      I am convinced that production code should not be mixed with test code.
      So Eric is right about JUnitX, it does not fool the Security Manager.
      JUnitX uses a Proxy pattern in that it puts a minimal TestProxy in a
      production package which handles all the accessibility issues in Java
      without changing production code.

      Concerning #1, testing private stuff should be kept to a minimum,
      perhaps
      only testing private methods and not accessing private or protected
      fields.

      So that is partially another of my posts repeated but I hope that it
      answers
      the question above.

      Regards,

      Andreas.
    Your message has been successfully submitted and would be delivered to recipients shortly.