tungwaiyip.info

 

home

about me

links

my software

Media

Yucatán Photos

St Lucia Photos

Photo Album

Videos

Blog

< April 2006 >
SuMoTuWeThFrSa
       1
2 3 4 5 6 7 8
9101112131415
16171819202122
23242526272829
30      

past articles »

Click for San Francisco, California Forecast

San Francisco, USA

 

The Problem With Developer Unit Testing

It was a while back when I attended the Developer Testing Forum. The were many good presentations about what developer testing can do for us. It was closed with a captivating presentation by Kent Back. They were all good. Yet I left somewhat unsatisfied.

For one thing, most of us are already developer testing enthusiasts. It was really preaching to the converted. Most topics are rather uncontroversial. We all want more unit testing. Even pointy haired boss would say so.

The real question is, why doesn't everybody do it?

Here are a few common objections and my responses.

  1. We have no time - that's sad, and it will probably be paid later.
  2. Our software is monolithic and tightly coupled, making it unsuitable for unit testing - we know this is no way to build software, loosely couple is the way to go
  3. Unit testing is difficult

Unit testing is difficult? As a developer testing advocate, I maintain it is simple and beneficial. On the other hand there is also some difficulties I do not want to downplay. Perhaps this is the right time for me to lay them out.

1. It is hard to write program that can be controlled by another program.

It is hard enough to find programmers who can write good program that functions according to a spec. I think it is a lot harder to expect programmer to write program that be also be controlled by another program, which is what unit testing requires.

There is one class of program that can be easily controlled by another program, that is utilities. This is not surprising because by definition utilities is a small piece of code to be called by another program to carry out some functions. There is also little surprise that many literatures focus on testing utilities, which is the low hanging fruit in unit testing.

Unfortunately most of the code written are not utilities. They interact with users, read and write to the database and the disk, control the flow of other processes. They react to and change system states. Testing these code requires design and instrumentation and demand more sophistication from programmers.

2. Techniques are in its infancy and are not well publicized

Since utilities are easy to test, one thing to do is to identify logic embedded in main body of code that is better isolated into utility functions. Queuing, sorting, searching and various algorithm are everywhere. It will a big win to isolate them just by the virtue that a feature can be tested much more easily.

The point I want to make is there are techniques like above for better unit testing. But they are often in its infancy and are not well publicized. Just like good programming, good unit testing is not easy to come by.

3. Extra level of abstraction can complicates design

Since we cannot always replicate the exact context for invoking the tested code, we often parameterize the code so that we can pass in a mocked environment. For example fetch_record() may means fetch from the database in the module. But since we rather not use the database in unit testing we parameterize it to take an extra resources parameter. In runtime context it will be the database. But in unit test context it will be an artificial data source.

In some case we find the added layer of abstraction actually improve the code because it is no longer hard coded to work in a single context. On the other hand flexibility come at a cost, no matter how small it may be. Having a few configuration variables and the complexity starts to multiply.

While complex and monolithic code is obviously undesirable, how is highly flexible, highly configurable code compares to a piece small and well integrated code? When simplicity is a virtue, flexibility can be a liability.

4. Test to death

Unit testing is a key tool in agile programming. You can be bold in refactoring when there is a suite of unit tests to back you up. Ironically extensive set of unit testing can also become the cement that harden your code and make changes difficult. If you diligently add tests for every subprocess of your code, chances are a lot of them will break when you change the code. It doesn't necessary mean your code has problem, it only means you have to maintain the test code and adapt it to the new version. It is arguably more difficult than changing to code itself because first you have to distinguish between a real problem from symptoms than merely need up keeping. On one hand unit testing give you the confidence to refactor. On the other hand too detailed testing can bog you down.

Finding the right level of test that cover the function but not so rigid that it breaks easily is also an art to master.


I have cited these few problems I have experienced not to suggest developer testing is not valuable. Instead I want to bring up a discussion that there are skills and technique required for successful testing. Also many issues can be mitigated by better tools and better programming language like AOP.

2006.04.15 [] - comments (0)

 

 

Comments (0)

past articles »

 

BBC News

 

Deadly blasts hit Pakistani city (12 Mar 2010)

 

BA union announces strike dates (12 Mar 2010)

 

Siberian tigers die at China zoo (12 Mar 2010)

 

Rove 'proud' of US waterboarding (12 Mar 2010)

 

NY approves 9/11 dust payout (12 Mar 2010)

 

UN critical of Israel over Gaza (12 Mar 2010)

 

Lehman bosses severely criticised (12 Mar 2010)

 

Sarkozy to meet UK party leaders (12 Mar 2010)

 

Thalidomide effect mystery solved (11 Mar 2010)

 

How one group of Viking 'visitors' was dealt with by Anglo-Saxons (12 Mar 2010)

more »

 

Slashdot News for nerds, stuff that matters

 

MetaLab Accuses Mozilla of Ripping Off UI Elements In Mockups (2010-03-12T02:08:00+00:00)

 

William Shatner Takes On Social Networking (2010-03-11T23:22:00+00:00)

 

Researchers Beam 230Mb/sec Wireless Internet WIth LEDs (2010-03-11T22:38:00+00:00)

 

SolarPHP 1.0 Released (2010-03-11T22:18:00+00:00)

 

Best Smartphone Plan Covering US and Canada? (2010-03-11T21:54:00+00:00)

 

Pennsylvania CISO Fired Over Talk At RSA Conference (2010-03-11T21:07:00+00:00)

 

Half-Male, Half-Female Fowl Explain Birds' Sex Determination (2010-03-11T20:48:00+00:00)

 

T-Mobile's First HSPA+ Modem Goes On Sale Sunday (2010-03-11T20:24:00+00:00)

more »

 

TechPsychic Tech Rumors and Invented News

 

TechPsychic: Opera Mini Stats Tell Google Chrome Release Adds Support high-definition video. (12 Mar 2010)

 

TechPsychic: MySpace recently launched Android On Twitter 1 Million Downloads A job applicant are alive, Facebook? (11 Mar 2010)

 

TechPsychic: Android Apps. (11 Mar 2010)

 

TechPsychic: Why Google starts at ReadWriteWeb hosted With the other partners, Skype Hits 521 million funding from iPhone. (11 Mar 2010)

 

TechPsychic: He's Learned: Facebook Connect. (11 Mar 2010)

 

TechPsychic: Top paid for the FTSE 100, the future. (11 Mar 2010)

 

TechPsychic: Opera Software, Facebook During Apple's iPad Comes along, Windows Vista. (10 Mar 2010)

 

TechPsychic: JB: Why AT&T data plan? (10 Mar 2010)

more »

 

SF Gate

 

Pleasanton brothers ran meth lab, cops say (2010-03-11T16:52:49UTC)

 

Supes skeptical about Newsom's layoff plan (2010-03-11T18:26:24UTC)

 

Going got tough, Newsom got outta here (2010-03-11T08:21:35UTC)

 

Crime lab fallout: Drug defendants go free (2010-03-11T13:56:43UTC)

 

Fire in S.F. burns 2 buildings (2010-03-11T19:14:07UTC)

 

Whitman takes heat for avoiding reporters (2010-03-11T19:13:52UTC)

 

Highway deaths drop to lowest level since 1950s (2010-03-11T20:45:00UTC)

 

Lesbian teen sues Miss. school over prom flap (2010-03-11T23:09:25UTC)

 

Stocks climb for 3rd day as financial shares rise (2010-03-11T22:56:50UTC)

 

Slowly, Americans are regaining their lost wealth (2010-03-11T22:56:50UTC)

 

Rates are mixed after strong 30-year bond auction (2010-03-11T22:56:49UTC)

 

Citigroup CEO says bank on path to profitability (2010-03-11T22:55:48UTC)

 

Watson says FDA approves 6-month dose Trelstar (2010-03-11T22:51:48UTC)

 

Xoma 4Q profit falls as contract revenue tumbles (2010-03-11T22:49:43UTC)

more »

 

Asia Times Online

 

ALL ROADS LEAD TO KABUL : India seeks a new direction (Thu 11 Mar 2010 19:00:00 +0700)

 

Iran wants help from a friend (Thu 11 Mar 2010 19:00:00 +0700)

 

China-US ties strained like never before (Thu 11 Mar 2010 19:00:00 +0700)

 

US, Indonesia in a tentative embrace (Thu 11 Mar 2010 19:00:00 +0700)

 

India's cyber-defenses full of holes (Thu 11 Mar 2010 19:00:00 +0700)

 

DISPATCHES FROM AMERICA : Premature withdrawal in Iraq (Thu 11 Mar 2010 19:00:00 +0700)

 

Sri Lanka locks horns with UN (Thu 11 Mar 2010 19:00:00 +0700)

 

Reqo Diq mine at melting point (Thu 11 Mar 2010 19:00:00 +0700)

 

Locks turn in Nabucco door (Thu 11 Mar 2010 19:00:00 +0700)

 

China lassoes its neighbors (Thu 11 Mar 2010 19:00:00 +0700)

 

Job creation squeezed (Thu 11 Mar 2010 19:00:00 +0700)

 

THE MOGAMBO GURU : Debt doom ahead (Thu 11 Mar 2010 19:00:00 +0700)

more »

 


Site feed Updated: 2010-Mar-12 03:15