Click here to Skip to main content
15,914,943 members

Welcome to the Lounge

   

For discussing anything related to a software developer's life but is not for programming questions. Got a programming question?

The Lounge is rated Safe For Work. If you're about to post something inappropriate for a shared office environment, then don't post it. No ads, no abuse, and no programming questions. Trolling, (political, climate, religious or whatever) will result in your account being removed.

 
GeneralI like unit testing and debugging private methods so u$ sucks today Pin
Ernst Iliov Stavro Blofeld6-Oct-14 11:52
Ernst Iliov Stavro Blofeld6-Oct-14 11:52 
GeneralRe: I like unit testing and debugging private methods so u$ sucks today Pin
CDP18026-Oct-14 12:07
CDP18026-Oct-14 12:07 
GeneralRe: I like unit testing and debugging private methods so u$ sucks today Pin
Jörgen Andersson6-Oct-14 18:55
professionalJörgen Andersson6-Oct-14 18:55 
GeneralRe: I like unit testing and debugging private methods so u$ sucks today Pin
Agent__0076-Oct-14 19:12
professionalAgent__0076-Oct-14 19:12 
GeneralRe: I like unit testing and debugging private methods so u$ sucks today Pin
_Maxxx_6-Oct-14 19:34
professional_Maxxx_6-Oct-14 19:34 
GeneralRe: I like unit testing and debugging private methods so u$ sucks today Pin
Marc Clifton6-Oct-14 15:18
mvaMarc Clifton6-Oct-14 15:18 
GeneralRe: I like unit testing and debugging private methods so u$ sucks today Pin
_Maxxx_6-Oct-14 15:47
professional_Maxxx_6-Oct-14 15:47 
GeneralRe: I like unit testing and debugging private methods so u$ sucks today Pin
Marc Clifton6-Oct-14 16:21
mvaMarc Clifton6-Oct-14 16:21 
_Maxxx_ wrote:
one only cares what the results of public methods are.


True, because you have faith that the private parts (no pun intended) are doing their job correctly.

_Maxxx_ wrote:
If a public method calls zero or more private methods to produce an outcome, changes to any of those private methods don't matter, as long as the results of the public method remain unchanged.


OK, sure, there are public methods that need testing too, and yes, you can make everything public, but the point of private functions is to do, well, private stuff. So, if you have public functions that don't call any private functions, I would suggest that you delete those private functions as they are wasting space.

_Maxxx_ wrote:
What's the point of testing a private method that is used by a public method? It just means the private method gets tested twice.


That's not what I said. A good unit test engine needs to provide the ability to test the private functions, through reflection. In all likelihood (and certainly my experience) the public functions aren't worth testing.

_Maxxx_ wrote:
Although... if the private method accesses (e.g.) the database and so needs to be mocked, then it never gets tested - but then should one test such methods at all in a TDD environment (as it involves setting up and tearing down a whole database)...


A database interface is particularly annoying to test for the reason you stated. However, if you need to use a mocking framework to test functions that rely on the database, you've designed your code wrong. The DAL should be easily simulated by instantiating a simulation rather than some complicated mocking system. In other words, if you architect your code correctly, you don't need overly complex unit testing solutions.

I'm also not an advocate of TDD. Sometimes I write the code, walk it through the debugger, and I'm done. Othertimes, I write unit tests because I want regression testing for complicated stuff that might need bug fixes my test coverage doesn't handle. I actually never "write the test first." I find it a waste of time. I know a lot of people that get their jollies seeing little red indicators turn green when they write the implementation. Me, I think most of those tests are utterly pointless.

TDD should be used judiciously. I'll give you an example. I am in the middle of writing a SQL generator for CRUD operations on weird database architecture. I decided to first get some core behaviors implemented, like ridiculously simple queries, that I then wrote some tests for to vet out further. While I was writing the code, I made comments about "need to test this scenario" and "TODO: need to handle this condition". Those became good guidance for then writing other tests first that I knew would fail in the existing code, upon which I went back to the existing code and enhanced it (not fixed it) to handle those other conditions. I then repeated the process with other behaviors that I needed:

write a basic process
test it
expand the tests
revise the process

I find that that process works very well for me and keeps me focused on meaningful tests.

And no, I'm not testing unit level functions, I can do that perfectly fine by stepping through them in the debugger. In this case I'm testing the big honking function that glues everything together. However, if I were truly disciplined, I actually would be coding everything in nice small private functions and writing unit tests for those. As it is, there is a "TODO" on my big honking function that says "break this apart into smaller pieces" which I am disciplined enough to do next.

However, another thing that TDD doesn't really talk about is writing experimental code, and the idea of the tests is actually to prove or disprove that what I'm trying to do can be done and that my approach is solid.

Anyways, I'm rambling, but the point is, I see TDD misapplied because programmers don't understand the fundamentals of a good testing practice.

Marc

GeneralRe: I like unit testing and debugging private methods so u$ sucks today Pin
_Maxxx_6-Oct-14 18:09
professional_Maxxx_6-Oct-14 18:09 
GeneralRe: I like unit testing and debugging private methods so u$ sucks today Pin
Super Lloyd6-Oct-14 18:07
Super Lloyd6-Oct-14 18:07 
GeneralRe: I like unit testing and debugging private methods so u$ sucks today Pin
Marc Clifton7-Oct-14 2:26
mvaMarc Clifton7-Oct-14 2:26 
GeneralRe: I like unit testing and debugging private methods so u$ sucks today Pin
Nicholas Marty6-Oct-14 23:59
professionalNicholas Marty6-Oct-14 23:59 
GeneralRe: I like unit testing and debugging private methods so u$ sucks today Pin
peterchen7-Oct-14 0:32
peterchen7-Oct-14 0:32 
RantPHP PinPopular
Marc Clifton6-Oct-14 9:48
mvaMarc Clifton6-Oct-14 9:48 
GeneralRe: PHP Pin
CDP18026-Oct-14 9:54
CDP18026-Oct-14 9:54 
GeneralRe: PHP Pin
Afzaal Ahmad Zeeshan6-Oct-14 9:58
professionalAfzaal Ahmad Zeeshan6-Oct-14 9:58 
GeneralRe: PHP Pin
Marc Clifton6-Oct-14 10:13
mvaMarc Clifton6-Oct-14 10:13 
GeneralRe: PHP Pin
Jeremy Falcon6-Oct-14 11:24
professionalJeremy Falcon6-Oct-14 11:24 
GeneralRe: PHP Pin
Chris Maunder6-Oct-14 10:07
cofounderChris Maunder6-Oct-14 10:07 
GeneralRe: PHP Pin
Marc Clifton6-Oct-14 10:16
mvaMarc Clifton6-Oct-14 10:16 
GeneralRe: PHP PinPopular
Roger Wright6-Oct-14 10:13
professionalRoger Wright6-Oct-14 10:13 
GeneralRe: PHP Pin
CDP18026-Oct-14 10:16
CDP18026-Oct-14 10:16 
GeneralRe: PHP Pin
Jeremy Falcon6-Oct-14 10:32
professionalJeremy Falcon6-Oct-14 10:32 
GeneralRe: PHP Pin
Jeremy Falcon6-Oct-14 10:24
professionalJeremy Falcon6-Oct-14 10:24 
GeneralRe: PHP Pin
Slacker0076-Oct-14 10:29
professionalSlacker0076-Oct-14 10:29 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.