The Unit Testing Advocacy & Derision Thread

The story of the origin may be true (the XP folks came from smalltalk which is more or less dynamic) but it doesn’t mean that it’s useless in a language with static types. A type system can prove the absence of certain wrong behaviors, but it can’t prove the presence of a correct one. Of course in the absolute definition of “prove”, tests won’t do that either, but they do at least provide some assurances against regressions when you refactor code.

Regression tests have always been a major part of QA, and it’s just a consequence of the fact that dev machines have gotten so much more powerful that we can now write them preemptively, and run them with the push of a button.

White box & regression testing are awesome when need. I think that the original point however is that they’ve become fadish and are being used in places where they’re worthless. “It’s the write way to do it” (yes, I’m aware of my spelling there). Pointless white box testing is a waste of both computer (and worse) human time. As an example I’ve seen exhaustive test units for Remez method routines…WTF??? Think damn-you! Don’t just do because they say you should.

I think the takeaway is that tests should arise simultaneously with source and not as an afterthought after things break, and I’m convinced that’s still a good idea.

I’m not a fan of “test first” where implementation is an exercise in turning red bars green, no. To me, that’s a sort of dogma that actually hurts testing, since people may write sloppy tests just to bring coverage up, then write crappy code that just manages to turn the bars green. But really, no methodology can save a codebase written without any respect for craft.

BTW, what’s a “Remez method routine”?

A polynomial or rational (min-max approximation) of a function generated using Remez exchange method. (i.e. You know in advance exactly the set the values where the maximum error occurs and what the error is…so white-box testing is trivial)

BTW: When I said white-box testing a couple of post back…I meant black-box testing. Bad me.

Sorry for reviving this thread but I have to share.

For one month I have been working on a project with 3 other developers that got absolutely no clue what they are doing. When they try to fix something they always break 2 other things. The code is nearly unmanageable. The only thing that still save me are the unit test that I wrote. Every time they change something I can run my test and see if they broke something again. If one test fail, I refuse to merge their work into the main branch.

Really I think unit test were meant for case like that…

Indeed, testing becomes a Big F**ing Deal when you have multiple developers, since documentation isn’t always Ye Olde Tome Of The Holy Spec Volumes I-XVII – and even when it is, who wants to dedicate days or weeks to reading the spec when the API is supposed to define boundaries of acceptable inputs anyway?

Really I’d say that this is like just giving aspirin to someone seriously ill…treating the symptom and not the problem. The idea of test units should be to reduce engineering cost and not increase them, which sounds like what’s happening in this case.

Have you tried to manual test every little change that other, not so good, developers are committing to make sure they don’t crash the whole project?

Trust me it reduces engineering cost in my case… :emo:

A software system developed by even a small team of say ten developers is much too complex for every developer to have a full understanding of the system, or to fully foresee the effects of any given change. For this, unit tests are essential. If I was in a job interview and I was told ‘we don’t do unit testing here’, I don’t think I would take the job. At least, the money would have to be very good :slight_smile:

Hey, if you find a team that’s making money and they don’t do unit testing, it’s probably because they work well enough together not to need to waste their time on it.

Oh for design by contract. Sigh.

Cas :slight_smile:

You’re missing my point. Writing and running these test do not advance the project. Multiply the time your spending by two and that’s your opportunity cost of not progressing your project. The fact that you might be wasting less time than otherwise doesn’t change the fact your wasting time.

+1 for contracts.

Taking things out of context (or to their extremes) has rarely been associated with a good conversation, right?

Should we put too much effort into test code? No.
Should we put too little effort into test code? No.
Should we put just enough effort into test code? Yes.
How much effort is just enough? It depends.

Thanks for your valuable time! :-*

I thought unit tests was more of a “prevent errors” than “fix errors”.
In terms of large projects, I thought unit tests are more for “conforming your modules to design specs” rather than “fixing broken code”.

Using Unit Tests to fix code sounds, kinda silly. We have debuggers for that and they work rather well. I thought the reason companies spent so much time on unit tests so that modules written can work everywhere.

Does it waste a lot of valuable time? Hell yeah!
Is it beneficial to large coding groups? Depends.

It is exactly like what the first post stated about JUnit tests, it is just a way to plaster over the cracks of coders merging modules together. Why it takes up soo much development time really just depends on the coders themselves. “Writing tests is just a drag, and so is fixing your code to match those tests. Green checking is just boring… hack-and-slash code to get the green check. Yay!” Just because you hack code together, doesn’t make it robust or readable. But, alas, that is what JUnit tests promote when it comes to large coding groups.

We just want to code, not test. What is this, a driving school simulation? ::slight_smile:

I have never liked unit testing becouse it’s divide stuff in two places and that cause just too much headache. Nowadays I just use asserts to keep class invariants in shape and call it a day.

Invariants are great to have, but it still takes a test to verify that a corner case isn’t going to violate them. Otherwise, this is your story:

http://blogs.msdn.com/cfs-file.ashx/__key/CommunityServer-Blogs-Components-WeblogFiles/00-00-01-32-02-metablogapi/8054.image_5F00_thumb_5F00_35C6E986.png

Yeah but that’d be a system test wouldn’t it :slight_smile: And those are good.

Cas :slight_smile: