Wednesday 16 May 2012

Scott Hanselman User Group Tour of Scotland

Well I am not quite sure how they managed it, something to do with tracing his ancestry – I am sure he will could find a long lost uncle in Southampton/Bournemouth (mmm does anyone know anyone with the last name Hanselman in the local area?).

Anyway, here are the details for those that will be lucky enough to attend:

http://www.gep13.co.uk/blog/scott-hanselman-doing-user-group-tour-of-scotland/

http://www.hanselman.com/scotland

http://scottishdevelopers.com/2012/05/15/scott-hansleman-scotland-tour/

For getting the most up to date information regarding each of the events, make sure that you follow the following Twitter accounts:

The details for these sessions are as follows:

  • 9 July – Edinburgh: Developing for the Mobile Web

    Mobile traffic on the web is exploding. Are you ready? ASP.NET MVC 4 includes new mobile-friendly templates, a focus on responsive design as well as dedicated mobile templates that leverage jQuery and jQuery mobile. Scott Hanselman will show you what you can do today and tomorrow to make your site friendly on a mobile device. When should your mobile site become a mobile application? Should you use CSS3 media queries, or go “all in” and use jQuery mobile or another mobile framework?

  • 10 July – Dundee: Personal Productivity – Scaling yourself in the face of Information Overload

    As information workers, we are asked to absorb even more information than ever before. More blogs, more documentation, more patterns, more layers of abstraction. Now Twitter and Facebook compete with Email and Texts for our attention, keeping us up-to-date on our friends dietary details and movie attendance second-by-second. Does all this information take a toll on your psyche or sharpen the saw? Is it a matter of finding the right tools and filters to capture what you need, or do you just need to unplug. Is ZEB (zero email bounce) a myth or are there substantive techniques for prioritizing your life one the web? Join Scott Hanselman as we explore how you can be truly productive.

  • 12 July – Aberdeen: One ASP.NET – Open Source, .NET and the Cloud

    It’s an exciting time for ASP.NET and Open Source. What does the next version of Visual Studio and ASP.NET bring to the world of web development? How will you use HTML5, CSS3 and new advances in JavaScript with ASP.NET? There’s new advances in ASP.NET with the addition of real-time (Signalr), new features in WebForms as well as support for mobile. How will it all snap together in a way that makes sense? Join Scott Hanselman as he shares some internal documents and exciting surprises about the future of ASP.NET. What about Azure? We’ll talk about the world’s most misunderstood cloud and it means for developers of all flavours and persuasions.

  • 13 July – Glasgow: One ASP.NET – Open Source, .NET and the Cloud

    It’s an exciting time for ASP.NET and Open Source. What does the next version of Visual Studio and ASP.NET bring to the world of web development? How will you use HTML5, CSS3 and new advances in JavaScript with ASP.NET? There’s new advances in ASP.NET with the addition of real-time (Signalr), new features in WebForms as well as support for mobile. How will it all snap together in a way that makes sense? Join Scott Hanselman as he shares some internal documents and exciting surprises about the future of ASP.NET. What about Azure? We’ll talk about the world’s most misunderstood cloud and it means for developers of all flavours and persuasions.

Wednesday 2 May 2012

A breakdown of the Given, When, Then steps

In this post I try to explain what I think the various step blocks in the GWT structure are for.

Given

The “Given” part of a scenario is probably the hardest thing to implement and get right. The reason for this difficulty is that you have to balance the need for reducing complexity of the scenario by ensuring that only relevant context is stated whilst implementing the functionality to allow the context to be defined in this way. The “Given” step forms the configuration or setup phase, you are defining what context the scenario is running in and as such you need to manage datasets, add data, remove data, modify data, create users etc whatever is necessary to get the system into the correct state ready for the scenario to executed.

As an example, imagine a scenario where a member of a gym walks into a club, they have been sick for a long period so they “froze” their membership (this means paying a smaller amount for the duration of their sickness but keeping the membership open), and they ask the receptionist to unfreeze their membership.

The story:

Feature: Unfreeze membership
In order to resume a membership after returning from a long term sickness period
As a receptionist
I want to unfreeze a membership

The following two scenarios show two different ways of representing the same scenario, the first uses multiple Given steps to set the context where the second looks to simplify this into:

Example Scenario 1:

Scenario: Unfreeze regular monthly payer
Given a member joined on 01/01/2010 onto plan ‘Monthly’
And the member freezes their account on 01/02/2011 for 12 periods
And the current business day is 15/04/2011
When I unfreeze their membership
Then the member should be charged £10 freeze fee
And their status should be ‘OK’
And their payment status should be ‘Arrears’

Example Scenario 2:

Scenario: Unfreeze regular monthly payer
Given a frozen member
When I unfreeze their membership
Then the member should be charged £10 freeze fee
And their status should be ‘OK’
And their payment status should be ‘Arrears’

You can see that we have taken what was three separate steps has been combined into a simple “Given a frozen member” statement. The first thing you will probably ask is but what about the information such as join date and the freeze date and duration pieces of information, well what we really want to do here is have this information “inferred” so whenever members of the team refer to “a frozen member” they know that it refers to a member that joined on 01/01/2010 onto a monthly plan etc and we would set that information up as defaults which can be overridden if required. So you could do something like:

Given a frozen member with the following properties
| Key | Value |
| JoinDate | 15/01/2010 |

This gives us the ability to take all of the defaults of a frozen member and yet override them with values that are relevant and mean something within the current scenario. Keeping your Given statements concise and to the point plays valuable role in ensuring your tests remain readable and maintainable over the long term.

My personal preference is to make all “Given” steps non-UI based actions, this is because using the UI is the slowest and most brittle way to get things done and the point of the “Given” is to get your tests setup as quickly as possible.

When

The “When” phase is the event under test. This should be the main action that is being defined by the specification and I normally find this step to be the easiest to define and implement as it is the step that makes the call to the api or executes the UI automation code. There should be an obvious tie between the scenario title and the actions performed in the “When” steps otherwise you will have a mismatch between what you expected the specification to do and what it actually does.

Then

Finally, the “Then” phase is where you perform any assertions of correctness and you can run numerous checks and validations to ensure that the action that was performed during the “When” phase actually completed successfully and that all of the relevant data sets, files, databases etc have be been updated according to the expected behaviour.

When executing “Then” steps I try to use routes through the system such as alternative apis or use an external mechanism such as an Entity Framework, LINQ to SQL to validate databases or the .NET System.IO classes to validate the file system etc.