I have moved my active blog over to tumblr. I've maintained this blog for reference but will be posting to http://www.robustsoftware.co.uk instead. I've pointed my Feedburner feed to tumblr so if you're subscribed already you should already have switched with me.

Establishing Team Values

One of the biggest things I took from the Progressive .NET tutorials was the idea of establishing a set of values for your team.

This was raised in David Laribee’s session Towards A New Architect (watch out for the video of that coming out) where he asked whose team had a set of common values. In a room of 30 or so people, I think 3 or 4 raised their hand.

As soon as it was mentioned it made sense to me. A shared identity and core set of values can only benefit a team. To that end I’m going to run a similar session to the one I participated in in order to establish a set of values for my team.

I thought I might share the format I’m going to use so that others might do the same:

Set up a 1 hour session for discovering your team’s values

5 minutes explaining what we are doing and what we want to achieve

  • bring common values to the fore
  • give a common identity to the team
  • create a catalyst for improvement

DIVERGE, CONVERGE, SYNTHESIZE

  • 5 minutes writing words or short phrases down
  • 5 minutes converging to write all the different phrases on the board by going round the group
  • 2 minutes dot voting
  • 1 minute selecting top 3-5 by votes

DIVERGE, CONVERGE, SYNTHESIZE

  • 10 minutes to write a sentence explaining why each phrase is important (each person doesn't have to do each one)
  • 10 minutes coming together, taking each word in turn and sharing sentences all written on the board
  • 2 minutes tweaking and eliminating duplicates
  • 2 minutes dot voting each group of sentences
  • select the favourite sentence for each phrase

Your team now has a set of common values

Thank the team and tell them you are going to get them printed to put up on the wall. The important thing is that they are visible and prominent.

Important points

  • the number of values should be low – the messages should be simple and strong
  • the values should be visible to the whole team, all the time
  • everyone should be empowered to act to strengthen the values

I’ll blog about what values my team at Open Projects have chosen next week.

Great replication troubleshooting article

I found this article on troubleshooting replication woes, unfortunately it requires you to sign up for SQL Server Central. However, if you have the “pleasure” of dealing with replication it gives a lot of good pointers on sorting out problems so it’s worth it.

Related posts:

When geek rockstars go wild

Ok, a silly one but I’ve got to share this. When walking to the hotel on Sunday before Progressive .NET I saw this in the middle of the pavement:

smashed monitor

I’m guessing someone broke the build and this is what happened to their monitor.

Progressive .NET Tutorials

I will be attending the Progressive .NET Tutorials next week and I must say I’m looking forward to it. It’s slightly disappointing that Scott Bellware couldn’t make it for his testing track on Monday but there’s plenty of other things going on. This is my plan for the week:

Sunday

Travelling down from Nottingham with Andrew Bullock and checking into the Farringdon Travelodge down the road from Skills Matter. Nothing planned for this evening, probably get something to eat and then hit the hay before a busy few days.

Monday

Going to start the morning with Specification by example and Agile acceptance testing led by Gojko Adzic, it will be good to hear someone talk about testing as everything I’ve learnt has been picked up through screencasts and blogs.

For the afternoon I’m uncertain whether to go for Gojko’s FitNess.NET workshop or Sebastien Lambla’s workshop on OpenRasta. I think how well I get on with Gojko’s style of presentation in the morning will be the deciding factor.

In the evening I’m attempting to arrange a meal with other people from the tutorials then probably go to a bar for a drink or two.

Tuesday

I’m going to spend the whole day with Oren Eini learning about NHibernate. Again this is something I’m using already but all I’ve learnt is taken from the internet. Learning from one of the developers of NHibernate is an opportunity that cannot be missed.

In the evening Sebastien Lambla has arranged AltNetBeers where there will be an OpenConf style discussion. I’m looking forward to this nearly as much as the tutorials themselves.

Wednesday

Going to spend this day listening to David Laribee's thoughts on project management and teamwork. I’m hoping to come away from this with inspiration on how I can help improve my team’s practices.

Finishing it all off Skills Matter have arranged a trip to a pub for a drink or two. I’ll be spending about an hour there before catching the train back to Nottingham.

Thursday and Friday

I’m planning on blogging about the things I’ve learnt over the previous 3 days. So look forward to a raft of blog posts.

 

I might get chance to knock together a blog post, but I’ll be tweeting whenever I get half a second spare so follow me if you’re interested in what’s going on.

RhinoMocks IQueryable<T> helper

After reading Lee Brandt's post about how my answer to his question on Stack Overflow helped with testing the logic of his queries I realised that people might find one of my test helper extension methods useful.

I found that in my tests I had to mock out the Query<T> function quite a lot which would look something like this:

    1 protected override void EstablishContext()

    2 {

    3     var projects = new[]

    4                    {

    5                        Build.Project().WithName("AAAAAAA").Create(),

    6                        Build.Project().WithName("CCCCCCC").Create(),

    7                        Build.Project().WithName("BBBBBBB").Create()

    8                    };

    9 

   10     Mock<IUnitOfWork>()

   11         .Stub(x => x.Query<Project>())

   12         .Return(projects.AsQueryable());

   13 }

This was adding quite a lot of noise to my tests. I like to keep my tests as clean as possible to make them easier to scan when you need to review and understand them. Because of this I wanted to simplify the stubbing so there was as little code as possible.

This was made possible by this simple extension method:

    1 public static IMethodOptions<IQueryable<TEntity>> ReturnQueryable<TEntity>

    2     (this IMethodOptions<IQueryable<TEntity>> options, params TEntity[] items)

    3 {

    4     return options.Return(items.AsQueryable());

    5 }

The magic sauce in this is the items parameter. I’ve used the params modifier so that I can provide any number of TEntity objects for the IQueryable function to return.

This tidies the above setup code down to this:

    1 protected override void EstablishContext()

    2 {

    3     Mock<IUnitOfWork>()

    4         .Stub(x => x.Query<Project>())

    5         .ReturnQueryable(

    6             Build.Project().WithName("AAAAAAA").Create(),

    7             Build.Project().WithName("CCCCCCC").Create(),

    8             Build.Project().WithName("BBBBBBB").Create()

    9             );

   10 }

I find this much cleaner and easier to read, hope this helps someone out.

Happy testing!

Related posts:

A new name for ALT.NET

I will be attending Progressive .NET Tutorials next week and it got me thinking this morning.

Wouldn’t Progressive .NET be a much more positive and inclusionary name?

I’ve always felt the alternative part of ALT.NET to be quite elitist, exuding the feeling of “we’re different to you and that makes us better”.

Lets look at the dictionary definition of alternative:

  1. A situation which allows a mutually exclusive choice between two or more possibilities.
  2. A choice between two or more mutually exclusive possibilities.
  3. One of several mutually exclusive things which can be chosen.

It’s all about choosing between different things and can give the impression of “it’s our way or the wrong way”.

Progressive .NET (could be similarly shortened to PROG.NET) could soften the message of the ALT.NET movement whilst having the same meaning.

For contrast, lets look at the dictionary definition of progressive:

  1. Favouring or promoting progress; advanced.
  2. Gradually advancing in extent; increasing.
  3. Promoting or favouring progress towards improved conditions or new policies, ideas or methods:
    a progressive politician.
    progressive business leadership.

Isn’t progression of the craft of software engineering what ALT.NET is all about?

To be a part of ALT.NET I get the impression that you have to have mastered IoC, xDD, etc. before you can become a member. PROG.NET gives an altogether softer face, whilst still having the same ideals:

Want to improve your software? So do we, come join in.

Isn’t a message like that going to help ALT.NET cross the chasm? Then again, some will say what's in a name?

Difference between AreEqual and AreSame

This is a question I’ve been asked at work before and the answer is quite important as it can lead to tests mysteriously failing.

The difference between the two assertions are quite simple. Assert.AreSame checks that they are the exact same object, memory reference and all (in the case of .NET using ReferenceEquals). Assert.AreEqual checks that objectOne.Equals(objectTwo) will return true.

Here’s a simple example of how they will work with a sensible implementation of Equals.

    1 public class Example

    2 {

    3     private int variable;

    4 

    5     public Example(int variable)

    6     {

    7         this.variable = variable;

    8     }

    9 

   10     public override bool Equals(object obj)

   11     {

   12         if (obj is Example)

   13             return Equals(obj as Example);

   14 

   15         return base.Equals(obj);

   16     }

   17 

   18     private bool Equals(Example obj)

   19     {

   20         return variable == obj.variable;

   21     }

   22 }

   23 

   24 [TestFixture]

   25 public class Test

   26 {

   27     [Test]

   28     public void ExampleTest()

   29     {

   30         var one = new Example(1);

   31         var two = new Example(1);

   32         var three = new Example(2);

   33         var four = one;

   34 

   35         Assert.AreEqual(one, two);   // true

   36         Assert.AreSame(one, two);    // false

   37         Assert.AreEqual(two, three); // false

   38         Assert.AreSame(two, three);  // false

   39         Assert.AreEqual(one, four);  // true

   40         Assert.AreSame(one, four);   // true

   41     }

   42 }

So long as you have a sensible Equals method that compares the values of the two objects you can follow these rules:

  • If two objects are the same, they will be equal
  • If two objects are equal, they may not be the same
  • If two objects are not equal, they will not be the same

So now you’ll know the answer next time someone asks what the difference between Assert.AreEqual and Assert.AreSame is.

Related posts:

Feedburner RSS feed

I've become obsessed with statistics for this blog, no matter how small they are. To this end I've transferred my RSS feed over to Feedburner.

Anyone already subscribed shouldn't have to do anything as it should redirect automatically. However, you could resubscribe to be on the safe side.

 Subscribe to feed

Beauty of RSpec

I've only been using RSpec in anger for a short period of time but I'm in love with it already. It's support for BDD is fantastic. I'm now looking forward to the proper release of IronRuby even more than I was before.

I've only written a single class so far, but I'm delighted with the way the tests look so I thought I'd share them:


require File.expand_path(File.dirname(__FILE__) + '/../spec_helper')

describe "setting a person's password" do

given do
@person = Person.new
end

because do
@person.set_password "testing"
end

it "sets their password salt" do
@person.password_salt.should_not be_nil
end

it "sets their password hash" do
@person.password_hash.should_not be_nil
end

end

context "when someone has been saved" do

given do
@person = Person.new(:name => "tester")
@person.set_password "testing"
@person.save
end

describe "providing their credentials" do

because do
@retrieved = Person.with_credentials(:name => "tester", :password => "testing")
end

it "retrieves the expected person" do
@retrieved.should == @person
end

end

describe "providing the wrong password" do

it_raises "an error informing the password is incorrect", "Incorrect password" do
Person.with_credentials(:name => "tester", :password => "wrong")
end

end

end

describe "providing credentials for someone who does not exist" do

it_raises "an error informing the name is unknown", "Unknown name" do
Person.with_credentials(:name => "tester", :password => "unsaved")
end

end

The output when you run the tests looks like:

~$ rake spec:doc
(in /home/garry/code/rails/tinytweet)

setting a person's password
- sets their password salt
- sets their password hash

when someone has been saved providing their credentials
- retrieves the expected person

when someone has been saved providing the wrong password
- raises an error informing the password is incorrect

providing credentials for someone who does not exist
- raises an error informing the name is unknown

For those of you familiar with RSpec, you may notice that I'm not using the standard syntax. "given" and "because" are just aliases for "before". I've done this because I like the given/when/then style of tests but as "when" is a Ruby keyword and "it" helps you name the assertions properly for the docs it has become given/because/it.

I've also added an extra method "it_raises" as I found the way of testing that an error is raised rather clunky so I hid the nuts and bolts of it within my spec_helper.rb:

def it_raises(description, error_message)
it "raises " + description do
lambda { yield }.should raise_error error_message
end
end

No doubt I'll have more to share as my journey with Rails and RSpec continues.

Installing Ruby, Rails and RSpec on Ubuntu

So I had quite a nightmare with this one, but once I'd found the problem the installation was annoyingly simple. The crux of the problem is that Ubuntu's package manager will install old versions of both Rails and RubyGems that are not compatible with the latest version of RSpec and RSpec-Rails.

So, here's the steps I went through to go from nothing at all installed to a fully functioning Rails app with RSpec-Rails support:

  1. Use the package manager to install Ruby 1.8.7
  2. Manually download  the latest version of RubyGems from here (do NOT use the package manager for this)
  3. Extract and follow the instructions to install RubyGems
  4. Use RubyGems to install everything else:
  • [sudo] gem1.8 install rake
  • [sudo] gem1.8 install rails
  • [sudo] gem1.8 install rspec-rails

The last command will pull in the main RSpec gem as it is one of its dependencies.

Once you have created your rails app go to its directory run the command "script/generate rspec" then you're ready to rock and roll.