xUnit Test Patterns and evolving TDD and test automation

Published 11 June 07 05:18 AM | Sam Gentile

Cross-posted from my main Code Better blog
 

We went over 2,000 unit tests this past week during Iteration 72 on our Agile project. Of course, over the course of the last 18-24 months we have removed some tests, and in many cases, refactored the existing tests many times. We also have been learning a whole lot about TDD and the actual domain that we are building and testing. As we were doing this, we were implicitly discovering Test Smells, and discovering test automation patterns. The value in establishing patterns, and more precisely a pattern language in a particular domain are substantial. It's not so much that the "collector" of patterns is defining something new (some often mistakenly criticize pattern books in that regard) that you didn't know, but defining a shared terminology of our practices that we keep doing over and over. To that end, the patterns themselves not only define a shared vocabulary but serve other functions, not the least of which is learning from others. An obvious example of this is Martin's PEAA collection of patterns that enables us to say things like PageController or Lazy Load or TableDataGateway and we all know what it means. In fact, when I am talking about Interaction versus State/Behavior type of testing on CB, and others here use much of this terminology, I am in fact, talking about patterns like TestDoubles and MockObjects, among others.

When I became aware that Gerard Meszarous' xUnit Test Patterns book was going to ship Friday, I ordered it for overnight delivery on Saturday. I read well over 200 pages yesterday pretty much at one sitting, contented with a book that will change the face of the software industry, just as JUnit and all the other xUnit family have fundamentally altered software development for the better. Its definitely a big book at 944 pages, but it's not a book of excess, unnecessary pages. Rather it shows how hard it is to write defect-free software and the depth of the work that people are putting into this endeavor. The book uses Java as the language which obviously is no hardship to the C# programmer. Like most of the sound practices that have been evolving in the last ten years, this work has been evolving out of the terrific Java community.

Just like their are Code Smells, there are Test Smells, and writing good test code is just as hard and as worthy as writing good production code. Meszarous categorizes Test Smells into ProjectSmells, BehaviorSmells, and CodeSmells. Particularly interesting is his discussion in this regard to the commercial "record and playback" test automation products that have given test automation a bad name in many circles with their tendency to create FragileTests particularly with regard to Interface Sensitivity. Like many others, we were drawn in, and spent thousands of dollars with a vendor and exhibiting extreme Interface Sensitivity with the user interface. Their interface was not only unable to "pick up" most of the controls we use but even minor changes to the interface can cause tests to fail, even in circumstances in which a human user would say the test should pass. This only goes to support the notion many of us have talked about here about factoring a UI into MVP or MVC and not having logic in the "presentation."

Meszarous goes onto to provide very valuable discussions of Goals of Test Automation, Philosophies of Test Automation, and a Roadmap to Test Automation. Particularly what is important for Microsoft, and especially people like Euan who ask again about the vast difference between what we are talking about here/TDD and what they are talking about. We talk about things like Tests as Specification, also known as Executable Specification: "If we are doing test-driven development or test-first development, the tests give us a way to capture what the SUT should be doing before we start implementing it. They give us a way to specify the behavior in various scenarios captured in a form that we can then execute (essentially an "executable specification".) To ensure we are "building the right software", we must ensure that our tests reflect how the SUT will actually be used." We also talk about Tests as Documentation. Also, see Jay's piece on why even with Orcas its still not even there.

The main part of the book, of course, is the catalog of the patterns. Meszarous has provided a tremendous service to our community by not only cataloging and naming much of what we do, but also providing excellent discussions of why and how we do those things. I think, over time, this will be regarded as a seminal work in Software Development.

I'm rocking out to Do Not Pass Go by Frank Zappa from the album Guitar Disc 1

Comments

# Tomas Restrepo said on June 11, 2007 02:22 AM:

Thanks for the link to the book Sam, definitely looks pretty cool and I'll try to get my hands on it.

# http:// said on June 13, 2007 11:23 AM:

You don't need this methodology stuff.  Methodologies are a trap for the mind.  They are like the classical styles of fighting that kung fu fighters used before Bruce Lee came along - rigid styles that trapped their responses and stopped them from flowing.  Bruce Lee invented Jeet Kune Do, the styeless style.  Flow like water; do the thing that needs to be done directly, with a minimum of energy expended.  "Jeet Kune Do" is just a name, a boat to get you across the water; discard it when you arrive.

Jeet Kune Do can be applied to software development, as this guy pointed out in 2004:-

www.imnmotion.com/blog.jsp

And here is my response to his post:-

www.imnmotion.com/blog.jsp&response_id=33

# Sam Gentile said on June 13, 2007 11:58 AM:

Umm, there is no spoon?

# http:// said on June 13, 2007 01:21 PM:

Sam,

Not sure if there's a spoon or not.  I know that's a quote from The Matrix, but I'm not too sure what it means.

I've been reading your blog for years and visit it daily.  I'm fascinated by the stuff you write about.  Your appetite and enthusiasm for programming is amazing.  But I've always felt somewhat distanced from your angle.  After reading this post today, I finally put my finger on my ennui, and decided to post my thoughts.

For myself I feel freed from my self-inflicted guilt trip about NOT taking on all the stuff you write about (or even any of it).  For me the application of Bruce Lee's formless way, Jeet Kune Do, expresses how I think about methodologies, patterns, practices, etc. as used in software development.

IMO you have methodology cranked up to 11.  And that works for you, so that's great.  But if I were to do that, I know I would become trapped in methodology-think.  I prefer a more limber, fluid approach.

In a biopic of Bruce's life, he gives a nice demonstration of the formless way.  He asks a student for the guy's expensive watch.  Bruce chucks it up in the air and lets it fall.  The guy scrambles like crazy to catch it.  No fixed style or method or school... just CATCH MY WATCH BEFORE IT BREAKS!

I'm not advocating an unstructured, unschooled, uninformed, messy approach to software development.  But I am advocating for all developers to think for themselves about maybe NOT taking on methodologies which they may see as being unnecessarily restrictive.  I don't want to be  rejected for a job because I'm not agile or TDD or extreme or this and that, when I know full well that I can write code to a high quality in all respects.

The formless way is a valid option.  That's always been true, but I just wanted to point it out.

# Sam Gentile said on June 13, 2007 01:59 PM:

Thank you for the kind comments and your readership. I appreciate your comments and will think about what you said.

# Colin Jack said on June 13, 2007 07:56 PM:

Excellent, just ordered my copy (though I already haver about 20 books waiting for me to read them!)

# TrackBack said on June 14, 2007 10:28 AM:

testerqa.com/index.php

# TrackBack said on June 14, 2007 10:28 AM:

loopback.codebetter.com

# http:// said on June 15, 2007 01:29 AM:

Andrew,

My experience has been very similar to your own, ie practising a style of development that uses many and various techniques but without following a structured or mandated methodology.

However, I think the only major distinction going on is that between practitioners, formal teachers, and coaches.  Practitioners should be flexible and use the best tool or technique available for every job.  (And for certain projects a formal approach is in fact the best).  Formal teachers have only one major option available: to clearly enumerate, categorise and name techniques and to discuss their pros, cons, areas of effectiveness, and to provide examples of wide appeal and relevance.  Coaches on the other hand, offer advice to individuals with individual needs and this can range between single-instance advice, and general category advice.  Some formal teachers try to use the coaching styles, but it is often of limited appeal and not particularly useful as reference material. And I believe that formal teachers who try to explain their pracitioning approach 'as it really happens' are normally mis-stating the facts - the truth is normally far too convoluted to be serialized to text.  

I would suggest that Sam and others are working in two or three modes and that we mostly see the formal teacher side.  This is perfectly normal and appropriate, but the end result can be that practioners can feel isolated and disassociated from the formalisms.  However, formalisms don't actually get the work done.

I just wonder where Sam et al find the time.

# http:// said on June 15, 2007 02:02 PM:

Mike, thanks for your beautifully worded and reasoned response.  I totally agree that certain projects require a formal approach (which also indicates that others don't), and that's why I like to be as flexible as possible and not tie myself down to any one or two or three methodologies if I think they're misplaced.  I reserve the right to use no methodology.  I have a saying: "let the work decide".  The work / job / project  itself decides (or rather, informs me) how to approach it.  I do a lot of GUI work, and frankly I don't see how to apply unit testing to GUI work... so I don't use unit testing.  But it worries me to see firms proudly announcing: "We're Agile!", when even a cursory examination of their processes indicates that they're not.  I have heard from people who work for code shops where the (non-coding) manager comes back breathless from some conference to announce that they're going to be Agile or Extreme or this or that from there on in.  I think that the peer pressure to adopt methodologies that may be unsuitable is very real, even if that pressure is implicit and unintended...  ---------------------------------------- As regards where Sam et al find the time: agreed!  It's amazing!  ---------------------------------------- As regards your central thesis, this has helped me a lot to understand what is going on, especially on this blog.  I can see now that Sam and others probably are working in two or three modes, and what we mostly see is the formal teacher side.  I am 100% practictioner.  But us practictioners need formal teachers and coaches, and the contributions of Sam et al are most welcome.  However, the application of their formalisms must be carefully, appropriately and sensitively done (if they're done at all).  Of course there's scope for misapplication, and think we're seeing that happen right now with Agile/XP/TDD in certain firms, and this worries me.  ---------------------------------------- Do I feel inadequate when reading posts on this blog and on many others?  YES!  Definitely.  But now that is not the case because, thanks to you, I can keep in mind that I'm not a formal teacher or coach, I'm a practictioner and I don't have to accept this stuff (or even understand it!) if I don't want to, or if I feel that it's not appropriate.  And on a lighter note, this helped too: secretgeek.net/inadequate.asp

# Sam Gentile said on June 15, 2007 05:13 PM:

Thanks for both your very well worded comments. I think Mike captured it well: that I am functioning in 2 or 3 modes at once. Here, in this blog, I am trying to find that I am functioning as Teacher, even though many times I don't feel very smart or have a lot to offer :)

I appreciate your comments about Agile and my methodology approach Andrew. The weird dynamic is that after 15 years of "heavy methodology" I went over to Extreme Programming to escape that :)) I think a lot of us who were around in the early XP stage, almost did it as a severe reaction to the anti-pattern that was CMM! -))

Many of the XP folks on Ward's Wiki, and other places espouse Buddhist concepts to describe the mind sets and experiences of Extreme Programming and Agile. Many of the Agile practices are actually based on a high degree of self and team awareness. There a lot of practices that deal with being real to both oneself and to the team.

I would like to think that we have a hard time getting this down in words, on these blogs, and often times, come across as preaching and worse. I have called the Agile community on this on a post a short time ago. The actual process is a lot more organic and free-flowing than what comes across in the blog. The dynamic on the blog is trying to represent me trying to capture it and present it. Many times, I have to switch roles to do that and I get a little confused-))

This is a great discussion! Thanks!

# Colin Jack said on October 22, 2007 03:34 PM:

What do you think of this book now you've had a chance to read it?

Leave a Comment

(required) 
(required) 
(optional)
(required) 

This Blog

News

    The content of this site are my own personal opinions and do not represent my employer's view in anyway.

    Profile for SamGentile

MVP

Blog Information Profile for SamGentile

Syndication