CodeBetter.Com
CodeBetter.Com
RSS 2.0 via Feedburner
           Do you Twitter? Follow us @CodeBetter

Jeffrey Palermo [MVP]

Software management consultant and CTO, Headspring Systems

Having a baby and an integration testing tip - level 400

I found out today that my wife is with child, and we're having a baby!  Now, on with the post. . .

 

Integration testing isn't your basic 200-level topic at an MSDN event.  It can be very involved.  I believe that a good integration test has to depend on targeted unit tests being present.  Consider the scenario without unit tests:

Bob has a use case that spans 15 classes.  He sets up the environment to get this slice of the system under test.  He then proceeds to write the test with asserts.  He quickly becomes frustrated because for each of the 15 classes along the way, there are different scenarios that are possible.  If each class has just 2 possible uses, his number of scenarios to test are 2^15.  Each scenario requires many assert statements.  Faced with 32,768 test combinations, Bob is disgruntled and concludes that automated integration testing is too much overhead.

What did Bob do wrong?  First, Bob attempted to start his automated testing at the integration level.  Second, he assumed unit test responsibilities inside the integration test.  Third, he tried to test every possible combination of integration.  Fourth, he hadn't surrounded himself with a quality team that could help guide the testing strategy.

Here's the success scenario:
Bob has written unit tests for each of his 15 classes.  He marvels at how simple they looks since each unit test only has to cover 2 usage scenarios for each class.  With confidence that each individual class will do its job correctly, Bob writes an integration test for the use case choosing one of the many combinations that could occur.  Bob sets up the test, executes it, and then asserts on the resulting state of the system.  Bob finds an integration issues caused by how two of the classes interact with each other.  He fixes that bug, and the test passes.  Bob now has confidence that the 15 classes are interacting properly in his use case.

 

If you haven't already read the following from my friend, Jeremy Miller, take a minute to do so:

Qualities of a Good Unit Test: http://jeremydmiller.blogspot.com/2005/05/qualities-of-good-unit-test.html
Achieve Better Results by following Jeremy's Third Law of TDD: Test Small Before Testing Big: http://codebetter.com/blogs/jeremy.miller/archive/2006/05/30/145752.aspx


Comments

Jeremy D. Miller said:

Congratulations Jeffrey!

# January 25, 2007 7:56 AM

Ayende Rahien said:

Congratulations!

# January 25, 2007 10:23 AM

Javier Lozano said:

Congrats!  Welcome to the "Dad Club"!

# January 25, 2007 11:11 AM

Nick Parker said:

Congrats Jeffrey!

# January 26, 2007 3:17 PM

Grant McInnes said:

Fantastic news, mate! You will make a great Dad!

# January 27, 2007 10:20 PM

Jeffrey Palermo said:

Thanks, guys.

# January 29, 2007 7:38 AM

Noah Coad said:

Congratulations Jeff!!  Wow, somehow I missed this post till just now.  Guess it'll be Dawn and my turn next...  :)

# February 28, 2007 3:53 PM

Joseph Gutierrez said:

"Bob finds an integration issues caused by how two of the classes interact with each other.  He fixes that bug, and the test passes."

maybe instead of fixing bug. He writes a unit test to confirm an error in the interaction (One of the classes wasn't following it's contract). Now he fixes the bug. AND all tests pass.

Congrats! How many baby books do you have?

# May 12, 2007 11:58 AM

About Jeffrey Palermo

Jeffrey Palermo is a software management consultant and the CTO of Headspring Systems in Austin, TX. Jeffrey specializes in Agile coaching and helps companies double the productivity of software teams. Jeffrey is an MCSD.Net , Microsoft MVP, Certified Scrummaster, Austin .Net User Group leader, AgileAustin board member, INETA speaker, INETA Membership Mentor, Christian, husband, father, motorcyclist, Eagle Scout, U.S. Army Veteran, and Texas A&M University graduate. Check out Devlicio.us!

This Blog

Syndication