Saturday, 30 July 2011

Agile Cambridge: Creating a Walking Skeleton from Scratch

11am Thursday 29th December 2011

Come and see me at Agile Cambridge.


Starting with an (almost) clean IDE Paul will develop a Walking Skeleton.

The walking skeleton was described by Alistair Cockburn as "... a tiny implementation of the system that performs a small end-to-end function. It need not use the final architecture, but it should link together the main architectural components. The architecture and the functionality can then evolve in parallel." It is also one of the theme's in Freeman & Pryce's Growing Object Orientated Software Guided by Tests.

In this session Paul will start with an (almost) clean IDE and develop a walking skeleton for a simple application and demonstrate how Test Driven Development (TDD) can be used even at the system level to test features.


Husband, father, software consultant, author, testing and agile evangelist.

Paul has been programming in one form or another for over 20 years and has been involved in building agile teams since 2007. After several years of C++ and a very happy period using Java, Paul is now developing predominantly in C#.

Paul has worked in industries as diverse as marking machinery, direct mail, mobile phones, insurance and Internet TV. He is currently contracting at an investment bank at Canary Wharf.

When he's not programming or chasing his 2.5 children, Paul thoroughly enjoys science fiction, heavy metal and cycling.

Friday, 22 July 2011

Mocking C++

This month’s ACCU London was at 7City to hear Ed Sykes tell us about a couple of C++ mocking frameworks, MockIt Now and HippoMock. Ed is a very relaxed, confident speaker and the code and demonstrations he used were simple, straight forward and easy to understand. I mostly came a long to meet Ed as he’s an excellent contributor to the ACCU and specifically the Mentored Developers projects.

Ed obviously hit a chord with the audience and there was plenty of interaction and question asking. There were even a few tangents that Ed handled brilliantly. It looks like both of these frameworks use quite a bit of compiler magic and function pointer repointing, along with macro magic to achieve in C++, what is easily achieved with reflection in the likes of Java and C#.

Following the short presentation there was a long discussion on the more general topic of mock objects. Even though I haven’t used C++ for a little while, this presentation was absolutely fascinating and I will definitely be using a mock framework on my next C++ project.

Wednesday, 20 July 2011

Behavior Driven Development

While collaborating on a new article I was recently pointed in the direction of Behavior Driven Development (BDD) by Chris O’Dell. I only thought I had a vague idea of what it was before and I got so absorbed in Behavior Driven Development on Wikipedia and Dan North’s Introducing BDD today that I missed my stop on the tube. I never miss my stop on the tube!

There are two main points that stood out for me.

I usually develop software inside out. Start with the model and then add the user interfaces on top. Dan North tells us that the first thing that we should do is get the user interface going and then show it to the customer/user to get immediate feedback. This is actually far more sensible as the user interface is what the users see and use, so they can tell you if it’s right or how it needs to be changed. Then you can develop the model to suit, rather than the other way around.

For while now I have been looking for a good way to record acceptance criteria with user stories and I think I’ve found it. Dan gives and example of an ATM:

To illustrate, let’s use the classic example of an ATM machine. One of the story cards might look like this:

+Title: Customer withdraws cash+
As a customer,
I want to withdraw cash from an ATM,
so that I don’t have to wait in line at the bank.

So how do we know when we have delivered this story? There are several scenarios to consider: the account may be in credit, the account may be overdrawn but within the overdraft limit, the account may be overdrawn beyond the overdraft limit. Of course, there will be other scenarios, such as if the account is in credit but this withdrawal makes it overdrawn, or if the dispenser has insufficient cash.

Using the given-when-then template, the first two scenarios might look like this:

+Scenario 1: Account is in credit+
Given the account is in credit
And the card is valid
And the dispenser contains cash
When the customer requests cash
Then ensure the account is debited
And ensure cash is dispensed
And ensure the card is returned

Notice the use of “and” to connect multiple givens or multiple outcomes in a natural way.

+Scenario 2: Account is overdrawn past the overdraft limit+
Given the account is overdrawn
And the card is valid
When the customer requests cash
Then ensure a rejection message is displayed
And ensure cash is not dispensed
And ensure the card is returned

Both scenarios are based on the same event and even have some givens and outcomes in common. We want to capitalize on this by reusing givens, events, and outcomes.

Of course there is a lot more to BDD, than I have described here, but these are the inspirational particles for me.

Friday, 15 July 2011

An Introduction to the WPF with the MVVM - Part 1

After three wonderful years working with Java I am back in the C# arena and amazed by how things have changed. When I was working with C# previously it was with .Net 1.1 and as I return .Net 4 is ready to go. I started a new contract and my client suggested that to get ahead of the game I should learn Windows Presentation Foundation (WPF), the latest Microsoft framework for creating Windows desktop (and web) applications. It replaces the likes of Windows Forms on the desktop. Two of the major features of WPF are that it is rendered entirely on a computer's graphics card and separates presentation from presentation logic.

Manning is my preferred technical book publisher, so I bought the PDF version of WPF In Action with Visual Studio 2008 and read it on my Kindle. It is a great introduction to producing Graphical User Interfaces (GUIs) with WPF, but I later discovered that although Model-View-ViewModel (MVVM) is covered, the detail is not great. The MVVM pattern is similar to Martin Fowler's Presentation Model, but where the presentation model is a means of creating a UI platform-independent abstraction of a view, MVVM is a standardised way to leverage core features of WPF to simplify the creation of user interfaces. Fortunately there is a great MSDN Magazine article called WPF Apps With The Model-View-ViewModel Design Pattern that explains it simply and in a fair amount of detail.

To demonstrate WPF with MVVM I am going to incrementally develop a small application which allows the user to search an archive of books. The application is called Canon and the source code is available for download from my website. I developed Canon using Visual Studio 2010 and .Net 4, but WPF applications can also be created with Visual Studio 2008 and .Net 3.5. I have assumed that the reader is following along.

Read more. Originally published in CVu.

JVM Cloud Platforms

Tonight kicked off with the usual high quality lightening talks that I have come to expect form the London Java Community.

The two main presenters spoke individually about the cloud solutions that their individual companies offered. I know little to nothing about cloud computing. The emphasis was centred around Platform As A Service (PaaS). It appears that most of the major players (Amazon, google, etc) do not provide a private PaaS for testing and development. I find this astounding, despite the fact that I have worked with at least one major vendor who makes it very expensive to have a development environment, but at least it was still possible.

The stronger of the two systems described seemed to be the offering from SpringSource. Peter Ledbrook (Grails Advocate and ACCU Mentored Developers mentor) is a very interesting speaker. He has clearly been bitten by live demos not working in presentations before and, alas, he was bitten again tonight. Although, the previous speaker also had a problem with his live demo.

The more I hear about cloud computing, the more interested I get. With the two offerings this evening there is the opportunity to try it for free to get a real feel for it. However, I just don’t have a sufficient interest yet or a cloud suitable application to make it worth the while. Maybe my next contract.

You can see the video here.

Thursday, 14 July 2011

One Test Or Two?

Paul Grenyer & Chris O’Dell

"I know what you’re thinking: “Is that two tests or only one.” Well, to tell the truth, in all this agility, I’m not sure myself. But this is Test Driven Development, the most power development technique in the world, and could give you clean code, you’ve got to ask yourself one question: Do I feel expressive? Well, do ya, punk?"<

Paul: I have a Windows Presentation Foundation (WPF) application that loads a list of widget names from a database and uses them to populate a drop down box. There is no default widget, so the user must select one from the list and click the load button to load it. The behavior is such that before a widget name is selected the button is disabled and cannot be clicked.

One pattern often employed in WPF applications is Model-View-ViewModel. The view model can use variations of the Command Pattern for processing commands from and giving feedback, such as the enabled state of a button, to the View. MVVM is intended to give separation between a view and its logic. Therefore the view model is usually devoid of User Interface (UI) code and easy to instantiate and run unit tests against.

I have a unit test that instantiates a view model and checks that the load command cannot be fired until a widget name is selected. A simplified version is show below, without the view model instantiation:

public void testThatExecuteIsOnlyPossibleIfNameIsSet()
model.Name = "Something";

Recently I have also been involved with the ACCU Mentored Developers project based around Growing Object Orientated Software Guided By Tests by Steve Freeman and Nat Pryce. In this book they write a lot about the naming and granularity of tests. So I posted the above code to the list and asked what the project members thought: “Should the above test be one test or two?”.

Chris: Without blinking I immediately replied that the above should definitely be split into two distinct tests so that a failure would be obvious from the test name. The above test has two asserts and as such either of these could fail.

Paul: Chris, and all the others who replied are of course right on the money (no one suggested it should only be one test), but something didn’t sit quite right with me. In this small example the extra code of two tests is not very much: the method definition, a pair of curly braces and some spacing. The problem for me is that test classes should not be treated that much differently to normal classes and any class with with a large number of methods becomes difficult to maintain and difficult to even to navigate. Although modern IDEs do make this easier with regions (C#) and code collapsing (Eclipse).

Chris: I firmly believe that it is worth the extra code - as many others also remarked, the five minutes now and extra curly braces could easily save twice that if you need to hunt down a related bug in future.

I went on to explain that in terms of application logic the two scenarios “with a name” and “without a name” are expected to be mutually exclusive and the two tests will ensure this by isolating each scenario and addressing them individually - with explicit test names.

In regards to the large classes this can be tackled by breaking your tests down into smaller classes, generally per scenario. For example, group all of the positive “happy path” tests together into one class and all the negative, error handling tests into another class and store both classes in a folder given the name of the class under test.

Paul: Again, Chris is of course right. Although the implication that a test method should only have a single assert is a whole other discussion.

Then Nat Pryce came along with another suggestion altogether:

“To really play Devil's advocate, I think there should be THREE tests!

1. The model initially has no name
2. The model cannot execute when it has no name
3. The model can execute when the name has been set.

You could squeeze that into two:

1. The model initially cannot execute
2. The model can execute when the name has been set

But I think the state transitions and constraints are clearer with three tests.”

Even with there now being the extra code for three functions, rather than one, this is of course the answer. It even satisfied the idea of one assert per method. The most difficult idea for me was not testing preconditions specific to a test if they were already tested in a another test .I have consequently modified my way of thinking and a lot of my test code.

Originally published in CVu July 2011.

Wednesday, 13 July 2011

The Last Programming Language

Tonight was mostly about entertainment and Robert C. Martin had me in stitches for most of the evening. He started off, as I gather he often does, by seeing who in the room could recite PI to any number of decimal places and how he lost a PI off to Herb Sutter.

Throughout his talk Uncle Bob mentioned most of the languages and paradigms of the last 60+ years and gradually brought us to the idea that nothing much that was really new has come about since around 1965. He went on to tell us that he thought that programming would converge into a single language. He even told us what that language would be, but I'm not going to spoil his surprise.

If you ever get the chance, go and listen to Uncle Bob! It's 100% geeky fun with a serious message. And I got my copy of Clean Code signed.

See the video here.

Sunday, 10 July 2011

Progressive Psychedelic Pulp

Hyde Park, Sunday 3rd July 2011.

I was only meant to be playing the role of taxi driver, but after most of the party dropped out, my wife talked me into going to Hyde Park to see Pulp with her. I wasn't really looking forward to it as I was expecting a 90 minute set with probably only a couple of songs I knew. I couldn't have been more wrong! There were only a couple of songs I didn't know!

We got to the festival just in time to catch Grace Jones. The best that can be said about her is that she has a great voice, but bad songs. She finished with a Roxy Music cover of Love Is The Drug and Slave to the Rhythm, so it wasn't all bad.

By the time Grace left the stage we'd been allocated some seats. Sometimes having a pregnant wife is an advantage!

I really wasn't expecting Pulp to do the big arena/festival thing either, but they did. They started with a big black curtain in front of the stage onto the back (stage side) of which they shone a lazer. A camera replayed what the lazer was writing to the audience via the large screens at the side of the stage: "Do you remember the first time?", "Are you ready?", "Again, are you ready?", etc. Then the curtain fell to the sound of streamers exploding into the crowd and there was Jarvis et al ripping through Do You Remember The First Time. From then on it was hit after hit including Sorted For Es And Whiz and Disco 2000.

I thought Jarvis would be too "cool" to stand on the monitors, but all he needed was a bass guitar and he could have been Steve Harris. He charmed the audience after every song proving what a great performer he is. The band was note perfect and the quality of the PA surprising.

Towards the end of the set Pulp did a couple of songs from the album that apparently followed Different Class. I could only describe them as Progressive Psychedelic Pop and really quite good, further proving what talented musicians they are. Then there was just time for a couple more hits, before the band, sensibly, didn’t waste time going off prior to an encore. Of course the final song was Common People, preceded by by a teasing description of St. Martin’s college form Cocker.

Was I impressed? Yes! Was I pleased I’d gone? Yes! Would I go to see Pulp again? Maybe.

Transformers: Dark Side of the Moon

We enjoyed the first transformers film, but didn't think much of the second. However the trailer for Transformers Dark Side of the Moon was excellent. The first ten minutes of the film, which featured the first moon landing, was superb. Then the film fell apart. It's not just that the Witwickey character is rubbish or the fact that the Autobots are a bit soft, but the language, the sex and the violence is way too much for a 12A.

Having seen the first two films we thought we were in safe territory. We'd taken our son for his 8th birthday, along with a friend, and my wife and I were wincing most of the way through. The language was very frequent and gratuitous, including at least one use of the F word. There was a lot of flesh on show in the opening scenes with Whitwiky. Once the film got going, there was a lot of gratuitous violence, including Transformers machine gunning humans in an office block through the window and Transformers vaporising humans leaving only a skull rolling away. What were the classifiers thinking?

As well as language, sex and violence the film just seemed to go on forever. There was a plot discrepancy where Megatron cuts Sentinel Prime's head off and a few minutes later it's on again when he fights with Optimus Prime.

Don't take your children to see this film.

Thursday, 7 July 2011

It's Always Nice To Get A Mention...

Please go along and read this new blog post by Agile Coach Rachel Davies on When To Write Story Tests.

Saturday, 2 July 2011

Threshold @ The Peel 2011

Threshold are simply amazing. Ok, so they are my favourite band, so I may be a little biased. I have seen them six times now, almost as many times as I've seen Terrorvision and the Wildhearts, and they get better every time.

Threshold should be playing places much, much bigger places than The Peel in Kingston, but I am so glad they aren't. In these tiny venues you can get right up and personal with the band. Not only that, but the band walked into the Pizza restaurant my friends and I were enjoying before the gig, Damian Wilson was on the door talking, as he always is and the remainder of the band were reportedly in the bar signing stuff after the gig.

With no support they played a stonking two hour set with something from every album except Psychedelicatessen:

The Ravages of Time
Long Way Home
The Destruction of Words
Sanity's End
Falling Away
Ground Control (acoustic version)
The Art of Reason
This Is Your Life
Pilot in the Sky of Dreams
Mission Profile

One Degree Down
Light and Space

Damian Wilson only sang originally on two of the songs in the set (Sanity's End and Clear), but he makes every song his own. At the end of a Fish gig I look forward to him pirouetting into the crowd during External Exile. Damian must have been into the crowd four or five times throughout the set, mostly due, I imagine, to the lengthy instrumental breaks in most of the songs. Forget Freddie Mercury, Damien Wilson is the ultimate frontman and his charismatic ability as frontman is second only to his incredible singing ability. It's going to be interesting to hear his vocals on a new Threshold album for the first time since 1998's Extinct Instinct.

I could listen to Karl Groom play guitar all night! In my opinion he is second only to David Gilmour, but he looks like someone's uncle! In fact all of the band and a lot of the crowd are firmly into middle age. Does it show in the heavy progressive metal they play? Does it stop the crowd being louder than the PA? Of course not!

I can't wait for the new album and to see them play again. If you only every see one progressive metal band, make sure it's Threshold!