ASP.NET Hosting

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.

4 Comments

  • 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.

  • 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!

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



    Exactly!

  • Andrew: good way to proceed.

Comments have been disabled for this content.