How test private function ?

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • PierpaoloScappatura
    New Member
    • Jun 2007
    • 4

    How test private function ?

    I need to test private function
  • r035198x
    MVP
    • Sep 2006
    • 13225

    #2
    Originally posted by PierpaoloScappa tura
    I need to test private function
    Are those all the details you're going to give us?
    Surely you can't expect us to make any sense out of that.

    Comment

    • pbmods
      Recognized Expert Expert
      • Apr 2007
      • 5821

      #3
      Heya, PierpaoloScappa tura.

      You can test private methods by temporarily making them public, or by modifying or creating a public method for the purpose of testing them.

      Similarly, you can test abstract methods or classes by commenting out the 'abstract' keyword until you're done testing.

      Comment

      • r035198x
        MVP
        • Sep 2006
        • 13225

        #4
        Originally posted by pbmods
        Heya, PierpaoloScappa tura.

        You can test private methods by temporarily making them public, or by modifying or creating a public method for the purpose of testing them.

        Similarly, you can test abstract methods or classes by commenting out the 'abstract' keyword until you're done testing.
        What on earth are you talking about?

        Comment

        • pbmods
          Recognized Expert Expert
          • Apr 2007
          • 5821

          #5
          Originally posted by r035198x
          What on earth are you talking about?
          Testing private functions.... Oh, I get it. I'm getting so high-level, that I'm practically an astronaut :)

          I dunno. OP put this in software development, so I just answered in terms of the context I'm used to.

          In PHP, if you need to unit test a private method of a class, you can make it public temporarily and then set it back to private when you're done testing (I mean by manually altering the source code).

          I can't recall ever actually having to do this, since I usually test my private methods as part of developing the public methods that depend on them, but everyone's got their own style, I suppose.

          Comment

          Working...