"When you're doing test driven development you often run into the issue where you want to test ... private/protected methods on classes."
Seriously?
I have found myself wanting to do just that but I've since attributed it to me being new to TDD at the time. How about you? I'd be interested to hear from TDD practitioners out there. Do you find yourself wanting to test something directly that's otherwise not visible to your test?
I'd genuinely like to know how such a situation arises. It's got to be that I'm missing something.
Have a read of the original post and background discussion.
Edit: I am really just being a purist? Does anyone read this and not shudder? "... an extension of JUnit which supports access to private and protected classes, methods and variables."
Sep 8, 2007
TDD & Testing Private Methods(?!)
Subscribe to:
Post Comments (Atom)
2 comments:
Private methods? For testing? Opened up? Nahhh!!! Y'ain't s'posed to test those. As a matter of fact the necessity to test a private method is a sure indicator of poor object structure. I write my tests to exercise the interface and only the interface. Private methods are not even all that common in my designs and when they are they are generally kept small. If there's a lot of logic tucked in a method private or otherwise then it's definitely a method that's doing too much. Check out Uncle Bob and what he says about S.O.C.h
Check this out! I just had a need to test a private method last night. It was on some code that I didn't write. and the private method was kinda big. So I just changed it to a public method and called it a done deal.
Post a Comment