Archive for March 23rd, 2007

March 23rd, 2007

Testy Confession

by Tim Cull

So I’m at SDExpo right now, and one of the classes I took was test driven development using Ruby on Rails. This is the point at which I have to make a confession:

I haven’t written a single test for my mystats project.

There, I’m glad I’ve gotten that off my chest. I have two very good excuses so I feel quite justified, but this week the second of those excuses fell:
1) I’m learning a totally new technology and can only learn so many things at once
2) I have no idea how to do unit tests in Rails.

I feel like I’ve started to get my Rails legs now and am transitioning from exploring to implementing, so the first excuse doesn’t hold much water any more either. So now I’ve got to suck it up and go back to write some tests. There are two immediate pieces of work I’m now going to have to go back and redo:
1) Drop my database named ‘mystats’ and create two different ones named ‘mystats_development’ and ‘mystats_test’
2) Throw out my DDL SQL script and replace it with a Rails migration.

I should have known to avoid this hassle, especially because the Rails documentation, books and blogs all took pains to point them out repeatedly, but I was learning so much new stuff that I wanted to stick with something I knew and just move on. I’ve walked away with the lesson reinforced yet again: “when in Ruby/Rails, do as the Rubyists/Railsies do.”

March 23rd, 2007

SDExpo Day 4

by Tim Cull

Day 4 I was surprised to run into someone else from my company here. He’s our resident test driven development advocate and had hand-picked Thursday because it had so many classes about it. The man can do truly unnatural things with JMock, and I mean that in a good way.

We started the day with a session on TestNG by Alex Ruiz. Our project is starting to reach the limits of JUnit so TestNG seems to be just what the doctor ordered. Some highlights:

  • It’s annotation based instead of inheritance and naming convention based.
  • It allows arbitrary grouping of tests together
  • It allows you to specify dependencies between groups and methods
  • It’s easy to write setup and teardown methods for suites, tests, classes and methods
  • It has a “JUnit” mode that lets you run existing JUnit tests alongside TestNG tests

Something else interesting I didn’t know before: JUnit re-instantiates your test class for each method it calls. So if you try to use a class-level instance variable, it’s not going to work. Not that you should anyway, but there it is.

Next we went to a session on emergent design through test driven development by Alan Shalloway. This class was awesome mostly because it gave me some ammunition to support a point I’d already been trying to make at work. Specifically, that one of the greatest benefits of test drivien development isn’t that you end up with tests, but that having to think about the tests first automatically leads you to good design, even if you’re not a good designer. He walked us through an example where just keeping testability in mind caused you to create an extensible and maintainable design.

Next we went to a class called “Advanced TDD”, but really all it was was a guy from Siemens talking about why he thought TDD was good. Really, we get it by now or we wouldn’t be going to a class called “Advanced”.

Also, I forgot to mention yesterday that I saw a presentation by Amazon about their S3 storage, EC2 “compute cloud” and their reliable messaging offerings. They sound pretty awesome, in particular EC2 charges only 10 cents per hour. That’s an entire server for only 10 cents! Great for times when you demand is really peaky and you need to scale (and de-scale. Is that a word?) very quickly.