Jez Higgins

Freelance software grandad
software created
extended or repaired


Follow me on Mastodon
Applications, Libraries, Code
Talks & Presentations

Hire me
Contact

Older posts are available in the archive or through tags.

Feed

The Forest Road Reader, No 110

I have a "usual" at London cafe. Unaccountably, this delights me.

Exploring strange new worlds - Writing tests with Spock.

For many years I was a happy CVS user. I might even qualify as a CVS early adopter. I kept everything in it - source code, tools, machine configurations, everything everything. I watched as Subversion was being built - which took a while - but even once it was clear that Subversion was now the thing to use, I didn't make the switch. I was happy with CVS. It did what I wanted.

Eventually, out of curiousity and (because there were RPM packages available so it was easy) I set up a Subversion server and migrated over one of my repositories. Within about half an hour I was moving directories around like a good 'un and kicking myself for not having looked at it years earlier.

I feel the same way about Spock. I've been using it for approximately an hour, and I can feel my Java TDD centre of gravity shifting. You can work quickly and accurately with it. There's so little scaffolding or boilerplate, you can whip up a new test or test suite in no time. The tests, sorry specifications, are clear and easy to read - consider this example

class HelloSpock extends spock.lang.Specification {
    def "length of Spock's and his friends' names"() {
      expect:
        name.size() == length

      where:
        name     | length
        "Spock"  | 5
        "Kirk"   | 4
        "Scotty" | 6
    }
}
and then imagine the JUnit equivalent. Even with JUnit4 you'd have a mass of assertEquals and duplication or a loop of some sort. There's some sophisticated stuff going on in the background and, bloody hell, doesn't it make the tests look great?

That's not even the best thing. What's best of all, I discover, is that because Spock is written in Groovy you really can write and run the test first before writing the thing under test. In Java (or C++ or C#) you can't really do that. You can kind of pretend, but you'll be hitting compile errors until you've at least written a stub. With Spock, you can (a lot of the time anyway) write the test, run it, see the error in the (wonderfully formatted) output and only then think about writing the code. It's a small thing, but it makes a much bigger difference that I'd ever have anticipated. I'm finally beginning to understand what Kent Beck and chums was so excited about all those years ago when they were first articulating what we now call TDD.

Installing Emacs groovy-mode. It's all kicking off!

OK, one more feature before bed ...




Jez Higgins

Freelance software grandad
software created
extended or repaired

Follow me on Mastodon
Applications, Libraries, Code
Talks & Presentations

Hire me
Contact

Older posts are available in the archive or through tags.

Feed