Unit testing strains
Posted by Jonas Elfström Mon, 05 May 2008 19:17:00 GMT
I've felt it and I've heard it from colleagues several times. Writing unit tests can be hard work. Especially adding unit tests to an existing code base is, at best, cumbersome. Also it's one of those things with delayed gratification. Sometimes it's not even you that will benefit from them being there because the biggest win can be long down the road, when changes to the system has to be made.
Tests may seem to be isolated and it's even considered a good thing to keep them that way. Even so the tests of your application has a correlation to what the system aims to do on a bigger scale. This one of the things BDD focuses on. I think that one of the biggest advantages is that you in one process writes a specification and tests that ensures that the spec. is met. Testing becomes a natural part of the development process. This way it clearly shows that BDD and TDD are design processes and that it's certainly not all about adding unit tests.
Find out more about BDD on: BehaviourDrivenDevelopment
It must be stressed that BDD is a rephrasing of existing good practice, it is not a radically new departure. Its aim is to bring together existing, well-established techniques under a common banner and with a consistent and unambiguous terminology.
For Ruby RSpec has almost become the de facto standard for BDD. The concepts Story, Scenario, and Test feels natural and the syntax is short and easy to read.
In languages like Java or C# the tests often becomes much more cluttered and some of that clutter is the extra code that comes with static typing. I believe that dynamically typed and overall dynamic languages like Ruby or Python could find a nice little niche here. They could become DSL's for testing.
RSpec is on it's way for .NET/C# via IronRuby and for Java via JRuby but don't hold your breath because they are still in alpha and beta.
.NET / C#
Testing .NET with IronRuby...
NSpecify => RSpec… well closer anyway
Java
Java Functional Testing with JRuby and RSpec
JtestR
Ruby
Slapp - A simple chat wall Merb tutorial. With nice exampes of using RSpec.
Behavior-driven testing with RSpec
ASP.NET MVC
ASP.NET MVC Test Framework Integration Walkthrough
MVC Preview - Testing
ASP.NET MVC Session at Mix08, TDD and MvcMockHelpers
For Ruby you could also check out Shoulda, an extension for Test::Unit. http://www.thoughtbot.com/projects/shoulda
http://pragdave.blogs.pragprog.com/pragdave/2008/04/shoulda-used-th.html
http://pragdave.blogs.pragprog.com/pragdave/2008/05/silly-shoulda-t.html
http://drnicwilliams.com/2008/07/04/unit-testing-iphone-apps-with-ruby-rbiphonetest/ - testing Objective-C with Ruby
It’s getting closer: http://blog.jimmy.schementi.com/#ir06cucumber