Can a test access private methods and properties?
Posted: Fri Jun 15, 2007 7:28 pm
N.B. - I'm using PHP 4.
Am I right in thinking that, in broad terms, tests should not need to access private properties of tested objects, or run private methods? I would say that this can lead to a dependency by the tests on the internal logic of the tested object, which is bad.
I ask because I've done it a lot in my first test-driven project - my test cases often start by testing smaller private methods first before the big public methods which utilises them. Of course, I could strip out the earlier tests and just test the public method, but there are some boundary conditions I find it hard to replicate if I'm only allowed to interface with public methods.
Thoughts, or links to previous discussions (I have searched but found very little), would be much appreciated. I can imagine this question has cropped up before.
Thanks!
Am I right in thinking that, in broad terms, tests should not need to access private properties of tested objects, or run private methods? I would say that this can lead to a dependency by the tests on the internal logic of the tested object, which is bad.
I ask because I've done it a lot in my first test-driven project - my test cases often start by testing smaller private methods first before the big public methods which utilises them. Of course, I could strip out the earlier tests and just test the public method, but there are some boundary conditions I find it hard to replicate if I'm only allowed to interface with public methods.
Thoughts, or links to previous discussions (I have searched but found very little), would be much appreciated. I can imagine this question has cropped up before.
Thanks!