As I mentioned in my last post I’ve recently taught a course in automated testing to a bunch of students at KYH. Before the course I spent some time looking for good course books for them. I looked at a few options and eventually decided on “The art of Unit Testing with examples in .Net” by Roy Osherove, and “The RSpec Book” by Chelimsky et al.

I chose the unit testing book because Roy does a good job of describing the basics of test driven development, including simple mocks and stubs. The book is very practical and is full of insight from experience and code examples.

I also looked at “Pragmatic Unit Testing in C# with NUnit” by Andrew Hunt and David Thomas. I’m a big fan of their book “The Pragmatic Programmer”, so I had high hopes for this one. Unfortunately I was rather disappointed with it. It talks about what good unit tests should look like, but not much about how you use Test Driven Development to create them.

I chose the RSpec Book because it has quite a bit of material about Cucumber and how it fits in to a Behaviour Driven Development process. I think the published literature on automated testing focuses too much on unit level tools, and there is not enough written about feature level tests and how to use them as part of the whole agile process.

I also looked at “Bridging the Communication Gap” by Gojko Adzic, which I think is an excellent introduction to how to use feature level tests as part of the agile process, but it is largely tool agnostic. There is a short chapter introducing some tools, including JBehave, a forerunner to Cucumber, Selenium and TextTest too. It’s a little out of date now though, and for this course I wanted something with more detail.

I hope these short book reviews are useful.

I’ve just spent 3 weeks teaching a class of 11 students about automated testing, as part of a one year course in software testing. The course is organized by the local “Kvalificerade Yrkes Högskolan”, KYH. (loosely translated: Skilled Trade University). The students come from all kinds of job backgrounds, from sitting in a supermarket checkout to driving trams to gardening, and most of them had never written a computer program before the course started.

The KYH tries to design their courses so that students will be competent enough to get a job by the end of them, so they work closely with local employers to set the curriculum and find teachers for the courses.

I was pleased to be asked to do this teaching job, since automated testing is one of my main areas of expertise, but at the same time I was quite daunted by the prospect. I’ve never taught non-programmers before, and I’ve certainly never had to set an exam or hand out grades. Before I agreed to do it, I spent some time talking to a friend of mine who has previously taught a different KYH course, and his story actually wasn’t all that encouraging. It’s hard work preparing the teaching materials, and some of the students will find it very difficult and need a lot of help and coaching. I decided it could be worth doing, anyway. I had some teaching materials prepared already, and I wanted the chance to invent more, try out some new ideas, and broaden my horizons.

Now that I’ve done the course I can attest that it really is hard work preparing lessons and exercises, and some of the students do need a lot of help. It is very rewarding though when they start to understand. I got a real kick out of going round the classroom seeing them all starting to write tests with Selenium and Cucumber, and answering their questions about Ruby and Page Objects and how to name tests and what to assert, and where to put the code and which parts to write tests for…

I think by teaching this course I’ve learnt a lot myself about things like how to communicate ideas, give feedback and encouragement, and to set boundaries and manage expectations. I found marking their work much more interesting than I expected, too. What kinds of mistakes do inexperienced programmers make when doing TDD? Do they find it easier to write good tests with Selenium or Cucumber? Is there any correlation between testing skill and programming skill? (short answers – they don’t refactor enough, Cucumber is way easier, and no, the correlation seems pretty weak)

So do I recommend getting involved? Absolutely! I think the IT industry in general needs more people in it from diverse backgrounds, and this is the kind of course that brings them in. If my experience is anything to go by, you’ll work hard but you’ll learn a lot from the students too. Networking with the other employers in the course Industry Reference Group is useful, and if I was looking to hire a junior tester I’d now know exactly who to ask first. Actually, who knows, in a few years some of my students might even be in a position to give me a job.

Don’t just complain that it’s hard to hire qualified people and/or people from diverse backgrounds. Get down to your local KYH equivalent and help them set up a course! I think that being a good software developer or tester is not restricted to only those with a degree in Computer Science. A course at a trade school where local employers get involved is good value for everyone.

This is the second time I’ve attended Nordic Ruby, you can read about what I thought last year here. This year I enjoyed the conference more, for several reasons. There were some small changes in the way it was organized, (on a Friday and Saturday instead of taking up a whole weekend), a better choice of speakers and topics, (less technical, more inspirational), and I knew more of the people there.

One of the themes of the conference was diversity, which I was very, very happy to see. There was an inspiring talk by Joshua Wehner about this topic, taking up some depressing statistics about the IT industry in general and open source software in particular. What struck me most was that he said the statistics for women involvement are improving in many formerly male-dominated disciplines, like maths, physics and law, but in computing, the situation was actually better 20 years ago than it is now. The curves are pointing the wrong way in our industry.

Having said that, there were slightly more women at the conference this year than last, I think I counted 4 of 150, compared with 2 of 90 last year. There were also far fewer references to science fiction movies from the speakers this year 😉

Joshua did take up several things that we could do practically to reduce bias and positively encourage diversity. He’s written about some of them in this blog post. Another one he mentioned that I liked was the “no asshole rule”. If people engage in arrogant one-upmanship, talk down to others, and emphasize their superior programming abilities, they should be regarded as not just annoying, but actually incompetent. Developing software is a multi-faceted skill, and it takes a lot more than just writing good code to be a good software developer.

Joe O’Brien continued the diversity theme in his talk “Taking back education” by basically arguing that having a degree in computer science correlates very badly with being a good software developer, and that we should be finding ways to bring people into our industry who have non-traditional backgrounds. He advocated companies to start apprenticeship programmes, while conceding that this model of education doesn’t scale very well. He talked about getting a group of companies together to set up a “code school”. He said “forget universities when it comes to education [of software developers]. We’re better at it”

I applaud his efforts to bring a more diverse range of people into the industry, and I think my recent experiences teaching a group like this are relevant. I think I’ll write a separate blog post about that experience, but basically I think the idea of a “code school” is a good one, and similar institutions probably already exist, and could add a course in software development to their programme of courses in practical skills. For this to happen it’s up to companies to put in time and energy setting them up, rather than just complaining that when they put out a job advert, all they get are white male applicants between the ages of 25-35, so it’s not their fault.

Another talk that deserves a mention is the one by Joseph Wilk. He spoke about “The Limited Red Society” which is an idea that Joshua Kerievsky came up with. I heard Joshua speak about it at XP2009, and I thought Joseph did a very good job of explaining what it is, and why it’s important.

Basically the idea is that although you need your tests to go red during TDD, if they stay red for any length of time, it can get you into trouble. While they are red, you can’t check in, ship your code, or change to working on a different task. This is one motivation for trying to measure, and limit, how much of the time your tests are red. It’s also about more generally improving the feedback we get for ourselves while we work. Professional sports stars spend time analysing and visualizing their performances (where balls land on a tennis court, footballers rates of passing etc). We programmers could benefit from that kind of thing too.

Joseph has invented a tool that helps him to track his state when doing TDD. It’s a simple monitoring program that makes a note every time he runs his tests. It’s not as elaborate as the commercial tool offered by Joshua Kerievsky’s company, but it does work with Ruby and Cucumber. Joseph also has his tool connected to his CI server so that it runs tests that have failed recently in his and others’ checkouts first in the CI test run. He also gathers statistics about individual tests, how often they fail, and whether they are fixed without the production code needing to be changed – a way of spotting fragile tests.

I think this kind of statistics gathering is really interesting and I think Joseph will just have more insights to share as he gathers more data and does more analysis. I’ve been experimenting with the tool provided by codersdojo.org for measuring my performance at code katas, but Joseph seems to be taking this all to the next level.

Overall I thoroughly enjoyed Nordic Ruby. (I still think it would be improved by some actual open space sessions though). I talked to loads of really interesting people, enjoyed good food and drink in comfortable surroundings, and listened to some people give excellent talks. Thanks for organizing a great conference, Elabs.

The classic description of TDD that most people know is the 3 rules by Bob Martin. I think his rules are a very succinct description, and for a long time I’ve just relied on them, together with a picture of “red-green-refactor” to describe TDD to newcomers. More recently I’ve found value in expanding this description in terms of states and moves.

When I’m doing TDD in a coding dojo using the Randori form, I get people stepping up to take the keyboard who’ve never done it before, and I find it helps them to understand what’s going on if I explain which state we’re in and what the legal moves are for that state. The picture I’ve used is like this:

TDDStatesMoves.001

I’d like to go through each state and some of the moves you can make in each.

intro coding dojo xp2011.016

I think before we start on a TDD coding session there is value in doing a small amount of analysis and planning. In the dojo, I’ll spend around 15 minutes in this starting state before we start coding. We’ll talk about the chosen kata so everyone hopefully understands the problem we’re going to solve. We’ll write a list of potential test cases on a whiteboard, and identify some kind of “guiding test”. This is an overarching test that will probably take us a couple of hours to get to pass. It helps us to define the API we want to write, and the goal for our session. We may also talk a little about how we’ll implement the solution, perhaps discuss a possible data structure or algorithm.

I know the group is ready to move on when we have sketched a guiding test or goal for the session, and have chosen the first test we’ll try to make pass.

intro coding dojo xp2011.017

When we’re getting to red, we’re trying to set up a small achievable goal. We’ll choose a simple test from our list, one that will help us towards our session goal (guiding test). This test should force us to address a weakness in our production code.

Starting with naming the test then writing the assert statement helps us to focus on what the missing functionality is. Then we can fill in the “act” and “arrange” parts of the test. I’m not sure who invented the “Arrange, Act, Assert” moniker for structuring tests, but the idea is that a test has three parts. In the “Arrange” part you set up the objects the system under test will interact with, in the “Act” part, you call the production code to do whatever it is, and in the “Assert” step, you check it did what you expected.

In a compiled language it helps to fill in a bit of production code while we’re writing the test, but only just enough to keep the compiler quiet. Once the test executes, and is red, you can move on.

intro coding dojo xp2011.018

This is where we flip over to the production code (I’ve seen newbies presented with a failing test trying to edit the test to make it green!).

If we can easily see what the implementation should be, we might just write it, but often it helps to return some kind of fake value, until we work out what the code should be. Sometimes in this state we find the test we wrote is too hard, and we need to get back to green by removing or commenting out the failing test. This is a sign we understand the problem better than we did before, which is a good thing. In that case, we’ll go back to “Getting to red” and write a better test. Otherwise, we get to green by making the new test pass.

intro coding dojo xp2011.019

The refactoring move is where we want to remove fake implementations, refactor away code smells and improve code readability generally. Don’t forget there may also be duplication and readability problems in the tests as well as the production code. The trick is to do a series of small refactorings that taken together lead to a better design. Try to stay only a few keystrokes away from a running system (green tests).

While we’re looking for refactorings, we’ll probably spot weaknesses in the production code implementation – functionality that is missing or cases that are not handled. This is a cue to note new test cases, not to fix the code. If we find a hard coded return value, say, we should be able to think of a new test case that will force us to write a better implementation.

We can move on when we’re happy the design of the code is good (for the test cases so far).

At some point hopefully we’ll find we can get our guiding test to pass, and/or that we’re out of time and the coding session is over. We’ll look through the code a final time, (as we check it in, maybe), then take a few minutes to reflect on what we learnt during this coding session. In the coding dojo, we’ll spend some time discussing what was good and bad about this dojo session, and what we might do differently next time based on what we’ve learnt.

The cycle begins again with the next coding task or the next dojo session.

The programme for DynCon has just been published, and the whole conference is about dynamically typed languages. There are talks about all sorts of languages, old and new, and I think it’s going to be really interesting to get people together from all these different communities. I’m giving a talk with title “A Test-Driven Introduction to Python” where I’m hoping to show off some of the best features of Python. I’ll also be demoing a new testing tool called “CaptureMock” which my husband Geoff has invented. I’ll be interested to hear what all the afficionadoes of other languages think of both it and python.

The programme for Scandinavian Developer Conference has been up for a while now, and I’m very pleased with the way its looking. The conference will be held in Göteborg in April, and I’m responsible for a whole track called “Conversation Corner”. I’m delighted so many people have agreed to take part, and I think we’ll be discussing some really interesting topics. I’m hoping it will be a really interactive part of the conference, as a complement to the other 10 tracks which mostly comprise presentations.

The programme for XP2011 also came out last week, although it is not yet complete. I’m Industry Chair for this conference, which will be held in Madrid in May, and I blogged before about my long association with this series of conferences. For this year, I’m still talking to people about putting together panel debates and discussions, and we also have space for more demos and lightning talks. The programme of tutorials and workshops is pretty much complete though, and I think we’ve got a great lineup of people leading them.

So I’ve got a very busy spring ahead of me with all these fantastic conferences coming up, and I’m thoroughly looking forward to all of them 🙂