Fabrice's weblog

Tools and Source

News

My .NET Toolbox
An error occured. See the script errors signaled by your web browser.
No tools selected yet
.NET tools by SharpToolbox.com

Read sample chapters or buy LINQ in Action now!
Our LINQ book is also available on AMAZON

.NET jobs

Emplois .NET

Tuneo

ASP.NET Hosting transatlantys

Contact

Me

Others

Selected content

Archives

Coding unit tests is even harder than you think

Jamie Cansdale has put a nice application online he calls Code Blog. This application expects you to write an implementation based on a set of unit tests.

This app shows how difficult Test-Driven Development (TDD) is.
Just look at the submissions for sorting a list (first challenge). They all work, but one was coded specifically for the test and won't work with something else but an ArrayList, and the other two depend on what you really want: a copy of the list or the list itself being sorted?
Jamie discussed about this.

If you look at the current challenge, for the TestToPlain8220() method, you'll realize that it's possible to code for that specific value "“", but the resulting method would not work with "‛" or "”"...

Just simple examples that TDD is hard, very hard. You have to accept that your unit tests will never be 100% complete. Code passing your tests cannot be considered bullet proof. It's just code that works with your tests.

Comments

TrackBack said:

# January 30, 2004 4:54 AM

Udi Dahan - The Software Simplist said:

Actually, the idea is to actually do the most trivial implementation to get the test to pass. The whole point is to get a suite of tests that sufficiently describe the system that needs to be built.

If you go about writing code to get a test to pass that does more than just get the test to pass ( think about that a second <g> ) - you're apt to not write the rest of the tests required to fully describe what code needs to be written. This is the path to damnation.

So, according to this, it's not that difficult to write code to get a test to pass. The hard part is coming up with the tests to write.
# January 30, 2004 11:33 AM

AndrewSeven said:

As you get closer to completing your code,the hard part is coming up with tests that make the code fail.

When you have a bug, instead of piddling around with the app/code, you write a test that causes the same bug.

When that test passes and all the previous tests still pass ... bingo!
# January 30, 2004 11:46 AM

Fabrice said:

Udi: "The hard part is coming up with the tests to write."

Exactly!
# January 30, 2004 11:53 AM

Fabrice said:

Andrew: good way to proceed.
# January 30, 2004 11:56 AM
Leave a Comment

(required) 

(required) 

(optional)

(required)