The Artima Developer Community
Sponsored Link

Java Community News
Cedric Beust on Test Extremism and Test-Driven Development

33 replies on 3 pages. Most recent reply: Mar 18, 2008 9:46 AM by Elizabeth Wiethoff

Welcome Guest
  Sign In

Go back to the topic listing  Back to Topic List Click to reply to this topic  Reply to this Topic Click to search messages in this forum  Search Forum Click for a threaded view of the topic  Threaded View   
Previous Topic   Next Topic
Flat View: This topic has 33 replies on 3 pages [ 1 2 3 | » ]
Frank Sommers

Posts: 2642
Nickname: fsommers
Registered: Jan, 2002

Cedric Beust on Test Extremism and Test-Driven Development Posted: Mar 5, 2008 9:11 PM
Reply to this message Reply
Summary
Cedric Beust, creator of TestNG and co-author of the book Next-Generation Testing, discusses the downsides of test-driven development, and shares his own testing rules-of-thumb in a recent blog post.
Advertisement

Quoting C++ expert Jim Coplien that

TDD leads to an architectural meltdown around iteration three...

Cedric Beust critiques strict adherence to test-driven development and shares his own testing rules-of-thumb in a recent blog post. Creator of the open-source TestNG testing framework, as well as co-author of the book Next-Generation Testing, Beust notes that:

When it comes to testing, I live by the following rules of thumb:

  • "Tests first" or "tests last" is unimportant as long as there are tests.
  • Try to think about testing as early as possible in your development process.
  • Don't let one liners contradict your experience. For example, don't listen to people who tell you to write "the simplest possible thing that could possibly work", also known as YAGNI. If your experience tells you you're going to need this extra class in the future even if it's not needed right now, follow your judgment and add it now.
  • Keep in mind that functional tests are the only tests that really matter to your users. Unit tests are just a convenience for you, the developer. A luxury. If you have time to write unit tests, great: they will save you time down the road when you need to track bugs. But if you don't, make sure that your functional tests cover what your users expect from your product.
  • Don't feel bad if you are not doing Test-Driven Development. There are a lot of factors that make this practice a bad fit for a lot of projects and developer personalities (aspects which are very often never mentioned by TDD extremists).

Do you agree with Beust that too much TDD can be harmful? And what are your testing rules-of-thumb?


Frank Silbermann

Posts: 40
Nickname: fsilber
Registered: Mar, 2006

Re: Cedric Beust on Test Extremism and Test-Driven Development Posted: Mar 6, 2008 7:23 AM
Reply to this message Reply
Yes, of course TDD can be harmful. It takes time; the task is sometimes annoying; and if you don't know how to write something in a way that it can be unit tested then your progress simply stops (unless you do research to discover how to do it).

It just depends upon how important it is for you to be able to keep your project from bogging down when aspects of the design later need to change. In a small one-man project that is sure to remain small, you'll always be able to refactor by using brute force that takes advantage of your ability to understand all aspects of the system.

Or you could do what many programmers do when having to modify code that someone else wrote: throw it all away and start over.

Merriodoc Brandybuck

Posts: 225
Nickname: brandybuck
Registered: Mar, 2003

Re: Cedric Beust on Test Extremism and Test-Driven Development Posted: Mar 6, 2008 7:39 AM
Reply to this message Reply
Let the madness begin...

Jesús Gómez

Posts: 1
Nickname: jgomo3
Registered: Mar, 2008

Re: Cedric Beust on Test Extremism and Test-Driven Development Posted: Mar 6, 2008 12:19 PM
Reply to this message Reply
Lot of time wasted developing TU's of some RPC Wrappers. There are so many causes not associated to the design that throws Error's on the RPC field that TDD is less effective than it is on other fields. Simple, There are domains were TDD is the MUST BE DONE and others were it should be avoided.

Maybe my example is a lack of my part and TDD have not relation at all, but i bet for the fact that there a certainly domains were TDD Bother.

Alan Keefer

Posts: 29
Nickname: akeefer
Registered: Feb, 2007

Re: Cedric Beust on Test Extremism and Test-Driven Development Posted: Mar 6, 2008 3:48 PM
Reply to this message Reply
I posted this on the original blog, but I figured I'd cross-post the comment here.

Good post . . . I largely agree with the general sentiment. I work at a place (Guidewire Software) that has over 36,000 unit tests running continuously, and we’ve tried just about every testing trick or methodology you can imagine, so I feel somewhat qualified to talk about the subject.

There are a few important lessons that we’ve learned. One lesson is that “unit” testing isn’t as valuable as you’d think and that higher-level tests (i.e. what functional tests) are more valuable. We’ve had situations where all the “unit” tests were passing but the application was totally broken because the parts didn’t fit together properly and we didn’t have enough higher-level tests to detect it. We’ve also gone from trying to mock out things like the database to just giving up and running our whole app stack in all our unit tests (including an H2 database). Basically, anywhere that the test code diverges from the app code paths is suspect for us; it leads to issues where the tests don’t catch bugs between components because the tests mock things out and the mocks don’t really properly encapsulate the full range of behaviors of something (mocking out a database being a good example), and it also leads to problems where simple refactorings of the code lead to test-fix death-marches where 6,000 unit tests are written expecting that some part of the app behaves in manner X, so a 2-day code change becomes quite literally requires a month of test fixing. So maybe that’s not how Coplien sees an architectural meltdown happening, but it’s what I’ve seen happen: your unit tests are a double-edged sword, and when you’ve still got tests hanging around from version 2.0 when you’re working on version 6.0 there’s going to be some serious drag from old tests just like there’s drag from old code.

The upshot is that bad tests are worse than no tests, since they just exert a huge amount of friction on your code base and actually make some changes harder. And some things are just inherently hard to test, and while that often means you need to rewrite the code in question it isn’t always worth it. I’ve seen TDD make code worse (i.e. harder to understand) by decoupling things so fully and behind so many different interfaces that it becomes much harder to follow. I’ve also seen TDD make code better by causing things to be decoupled in a way that actually works.

What I really, really hate is when the TDD/agile advocates blame the user instead of the tool. Too often the assumption seems to be that TDD/Pair Programming/Agile Practice X is perfect and that if it doesn’t work for you it’s because you’re doing it wrong. Not all writers write the same, not all painters paint the same, so why do people think all programmers program the same?

At the end of the day, my job as a software developer is about getting quality software that we can sell out the door in a timely fashion. That’s the metric against which all other things must be measured, and it’s always a trade-off. Sometimes it’s worth rewriting a class to make it testable, sometimes it’s not. Sometimes it’s worth spending 2 days fixing some tests, sometimes it’s better to just delete them. It all depends on your code base, project, time constraints, and team composition. Last time I checked, people have managed to write software for the last 30 or 40 years using tools that essentially look like rocks and sticks compared to things like IDEA or Eclipse or languages like Java and Python, so I’m guessing that there’s more than one way to properly develop a working piece of software.

TDD is a great tool, but being blind to its limitations or the tradeoffs that you have to make as a developer of real-world software isn’t a great way to develop.

Sergey Perepechayev

Posts: 1
Nickname: sergeyp
Registered: Mar, 2008

Re: Cedric Beust on Test Extremism and Test-Driven Development Posted: Mar 6, 2008 8:13 PM
Reply to this message Reply
When it comes to testing I live with the following rules of thumb:
* "Tests first" or "tests last" is important - the first one leads to a better design.
* Try to think about testing as early as possible in your development process.
* Listen to people who tell you to write "the simplest possible thing that could possibly work", also known as YAGNI. The simplest things are the most reliable.
* Keep in mind that functional tests are the only tests that really matter to your users. Unit tests are convenience for you, the developer that your modules work correct. Functional tests and unit tests cannot replace each other - these are the tests for different levels of software.
* Think of the reasons why you are not doing Test-Driven Development. There are a lot of factors that make this practice a bad fit for a lot of projects and developer personalities but it doesn't mean that the conception of unit testing should be thrown away.

Steve Merrick

Posts: 9
Nickname: erisian
Registered: Mar, 2008

Re: Cedric Beust on Test Extremism and Test-Driven Development Posted: Mar 7, 2008 3:59 AM
Reply to this message Reply
Unit-tests and functional tests have different purposes, as you appear to recognise. Is it really helpful to wonder if food or drink is more important? Without either, we'll die. ;-)

James Watson

Posts: 2024
Nickname: watson
Registered: Sep, 2005

Re: Cedric Beust on Test Extremism and Test-Driven Development Posted: Mar 7, 2008 7:07 AM
Reply to this message Reply
@Alan Keefer

Very well stated. I especially like the points about the possibility of all unit tests passing and whole application being broken. And I personally think that 'blame the user' should be considered a fallacy.

Cedric Beust

Posts: 140
Nickname: cbeust
Registered: Feb, 2004

Re: Cedric Beust on Test Extremism and Test-Driven Development Posted: Mar 7, 2008 10:45 AM
Reply to this message Reply
Hi Steve,

> Unit-tests and functional tests have different purposes,
> as you appear to recognise. Is it really helpful to wonder
> if food or drink is more important? Without either, we'll
> die. ;-)

I don't believe this analogy works: it's quite possible to create an application that implements all the needed features with just functional tests.

However, using only unit tests is a recipe for disaster, as was illustrated earlier in this discussion.

--
Cedric

James Watson

Posts: 2024
Nickname: watson
Registered: Sep, 2005

Re: Cedric Beust on Test Extremism and Test-Driven Development Posted: Mar 7, 2008 11:14 AM
Reply to this message Reply
> > Is it really helpful to
> wonder
> > if food or drink is more important? Without either,
> we'll
> > die. ;-)
>
> I don't believe this analogy works: it's quite possible
> to create an application that implements all the needed
> features with just functional tests.

Actually the analogy may be more fitting that it appears. We may need both food and water but we will die sooner without water than we will without food.

If you've ever been hiking in say, Arizona, you know that carrying water is crucial while food may only be needed on long hikes.

That's still a little strong of an analogy, though. I would say that functional (and regression) testing is crucial and unit tests are about efficiency.

I think we agree that there is a widespread confusion on that point.

Jeff Ratcliff

Posts: 10
Nickname: inhgtpoly1
Registered: Feb, 2006

Re: Cedric Beust on Test Extremism and Test-Driven Development Posted: Mar 8, 2008 11:05 AM
Reply to this message Reply
> * "Tests first" or "tests last" is important - the first
> one leads to a better design.

Frankly, I haven't heard about any empirical evidence to support this claim or even a convincing logical argument. What unique property of "test first" leads to better designs? Can you look at code and tell that it was created through TDD? Clearly there must be some good property in the final code design that is traceable to the use of TDD if your statement is fact.

I think "testing first leads to a better design" is supported about as well as "Things go better with Coke".

Jeff Ratcliff

Posts: 10
Nickname: inhgtpoly1
Registered: Feb, 2006

Re: Cedric Beust on Test Extremism and Test-Driven Development Posted: Mar 8, 2008 12:54 PM
Reply to this message Reply
> Hi Steve,
>
> > Unit-tests and functional tests have different
> purposes,
> > as you appear to recognise. Is it really helpful to
> wonder
> > if food or drink is more important? Without either,
> we'll
> > die. ;-)
>
> I don't believe this analogy works: it's quite possible
> to create an application that implements all the needed
> features with just functional tests.
>
> However, using only unit tests is a recipe for disaster,
> as was illustrated earlier in this discussion.
>
> --
> Cedric

I think if unit tests have a unique benefit, it may be in supporting code reuse. Functionality that was not used in a particular system (and thus had no impact on the outcome of the functional testing) might be used in another system, so unit tests support testing a unit as a "product".

Of course, the trade-off between delivering a system earlier and providing tested reusable code is something each project has to weigh on a case-by-case basis.

Paul Beckford

Posts: 51
Nickname: phaedrus
Registered: Feb, 2007

Re: Cedric Beust on Test Extremism and Test-Driven Development Posted: Mar 8, 2008 8:43 PM
Reply to this message Reply
> Unit-tests and functional tests have different purposes,
> as you appear to recognise. Is it really helpful to wonder
> if food or drink is more important? Without either, we'll
> die. ;-)

When I was first mentored in XP, the phrase used was "Test everything that can possibly break".

There are many things that can break in an application, hence many types of tests are applicable. E.g. integration tests, performance tests, load tests..etc, just to name a few. The issue is given time/effort constraints what is the most effective subset of tests cases that will work best for you? Many settle on unit and customer acceptance (functional) tests, but you can do more (or less) if you choose depending on what you think "will possibly break". Over time you will find out "what breaks" on your project and you can adapt your test strategy to suite.


Secondly TDD/BDD is not about testing, it is about programming and design. (I wish I had a pound for every time I needed to say this :)) Both these programming styles provide opportunities to get concrete feedback on your design through executable design specifications. The idea is to listen to your code and keep things as simple and as clean as possible (removing smells and refactoring as you go along). I was taught to reason about my design through tests. So if I felt a design feature was needed, I would need to find a way to express it as a test first. If I cannot find a test, then my reasoning and my intent is questionable. This approach to design works particularly well with pair programming, has each person has to justify their design ideas/intent with tests.


My 2 cents is that if more programmers where able to reason about their code in this way, then code bases would be a heck of a lot cleaner and succinct. TDD can make ordinary programmers look like coding geniuses. I agree with Bob Martin, I would place it as number one in the list of must have programming skills.

Paul.

Paul Beckford

Posts: 51
Nickname: phaedrus
Registered: Feb, 2007

Re: Cedric Beust on Test Extremism and Test-Driven Development Posted: Mar 9, 2008 12:34 AM
Reply to this message Reply
> > * "Tests first" or "tests last" is important - the
> first
> > one leads to a better design.
>
> Frankly, I haven't heard about any empirical evidence to
> support this claim or even a convincing logical argument.
> What unique property of "test first" leads to better
> designs? Can you look at code and tell that it was created
> through TDD? Clearly there must be some good property in
> the final code design that is traceable to the use of TDD
> if your statement is fact.
>
> I think "testing first leads to a better design" is
> supported about as well as "Things go better with Coke".

Have you read "Test driven development by Example" by Kent Beck? TDD is not about testing it is about programming and design (@ pounds richer :)).

Half the tests Kent writes are deleted as he goes along. You would never do this if you where just interested in testing. These are child tests written to give traction on understanding a bigger problem (divide and conquer). Once the parent test is complete the children can be safely removed. Kent also refactors his tests mercilessly to remove duplication. Your test in TDD is your first client for the Unit Under Test (UUT). If your test client contains duplication, then your real clients (the real code that will use the code you are testing) are also likely to contain duplication. Just the other day I saw duplication in my tests and this smell lead me to changing the interface to the UUT. This improved the interface to the UUT and hence my design.

This is all anecdotal I know, but if you read Kents book you are left in no doubt that TDD is a design tool. BTW I can tell just by reading code and tests whether the tests were written first or not. Test first code is more cleaner and succinct, also everything in the code is there to satisfy a test, and usually all the tests are there to satisfy design ideas that are readily mapped to the requirements.

Both tests and code are a lot cleaner and tighter with TDD without the tale tale flab that exists when programmers program by intent, putting in stuff they think they'll need later but never actually end up using.

I'm not saying that TDD/BDD is th only way to get clean. If you know how to produce "clean code that will work" then you should just go ahead and write it (after writing the parent test of course :)). When you aren't sure though (which is more often than most people are willing to admit) then you can take smaller steps and gain traction by breaking the problem up through child tests.


TDD allows you to write large lumps of code if you want by intent, or take small steps if that feels more appropriate. It is up to you.

Paul.

Paul Beckford

Posts: 51
Nickname: phaedrus
Registered: Feb, 2007

Re: Cedric Beust on Test Extremism and Test-Driven Development Posted: Mar 9, 2008 1:12 AM
Reply to this message Reply
> <blockquote>
> <p>TDD leads to an architectural meltdown around iteration
> three...
> </blockquote>
>

Jims original statement has some truth. If TDD is all you do then you are likely end up in problems. TDD is suited to small scale design at the scale of a few classes, for larger scale design and architecture then you need something else. XP talks about CRC Design where the team breaks out and does large scale design as a group exercise. It also mentions "Metaphor", as a way of communicating the overall architecture amongst the team.

I have found Eric Evans Domain Driven Design as an ideal tool for "design in the large". What ever you do though, eventually you need to define classes and interfaces in code, this is where TDD comes in. Smells found during coding TDD style may influence your high level design.

My experience is you need to be able to design top down and bottom up (as well as edges-in and centre out :)), so you don't have to throw away your old top-down design practices when doing TDD. The advantage of programming TDD style is what ever your design intent and how ever you got there, your design ideas are tested first. You are forced to write a test <b>before</b> you get to write code. If you can't express your design intent as a (relevant) test then your thinking/design is possibly flawed, in which case you get to write a child test and do some design bottom up.


Paul

Flat View: This topic has 33 replies on 3 pages [ 1  2  3 | » ]
Topic: Three NetBeans Evangelists Discuss NetBeans 6.1 Beta Previous Topic   Next Topic Topic: VisualVM Beta Released

Sponsored Links



Google
  Web Artima.com   

Copyright © 1996-2019 Artima, Inc. All Rights Reserved. - Privacy Policy - Terms of Use