Archive for February, 2010

The Agile Restaurant

February 18th, 2010

I've been doing Agile training again, and after yesterday's course I started thinking of a better way to explain what process means in an Agile world and how it differs from either an ISO-style paperfest or anarchy.  This is the analogy I came up with.

Think about dining in a decent restaurant.  There's a certain number of interactions you expect to  happen – you're going to be greeted and seated, you expect to  be offered an aperitif or water, you'll expect to see the menu and the wine list, and your going to expect your water, wine and dinner to be served.  If any of these steps are missed you're likely to feel annoyed, but also if you are asked every 5 minutes if you'd like to see the wine list, that's going to be annoying too.

There's a few ways round this.  In some places each waiter looks after a number of tables and only deals with those.  This means they always know the state of each table and are unlikely to repeat tasks.  The problem is this is quite inefficient. If we get a large party in and the rest of the room is quiet we'd like all our available waiters to help.  We also have specialists (like the sommelier) who is going to have to serve the whole room. We might also have junior staff (the guy who brings the water) who isn't yet ready to deal with more complex tasks.

The traditional prescriptive methodology approach would be to introduce some kind of table checklist. We'd have a set of boxes and tick off the tasks: has the water been offered? Have they seen the menu? and so on.  The maitre d' could then manage these table cards and allocate them to staff.  He can also 'report' on the status of the room to the owner by looking at the cards.  Sounds good?  Well it does offer a fairly strong guarantee that we will perform each table task exactly once, but we have introduced a major organisational task that's going to keep one of our seniors busy all night.  We've also prevented the team from being able to be proactive – if they spot a table where things don't seem to be happening they can't pitch in and help without getting approval from the supervisor. I think that's why this isn't how decent restaurants do it.

In reality, restaurants create a lightweight protocol to let each other know what's going on without the diner necessarily even knowing.  When aperitifs or water is offered they will place a bottle coaster on the table.  Each table might be set with generic wine glasses that are never used.  Once the wine is ordered (but before it arrives which might take some time) they will be removed completely if no wine is required or replaced replaced with specific white or red wine glasses.  The details will vary, but the principle is the same.

Any member of staff can see at a glance what state the table is in and deal with it accordingly.  There's a system, but it doesn't need a prescriptive process with a command and control structure.  The team can be proactive and deal with problems having confidence that they understand the situation and what is required – what does or doesn't need to be done.  That's the kind of system we want a self-empowered agile team working in.  We can't report by looking at cards, but we can look around the room and know exactly how will each table is doing which is what we really want to know, and we also still have a guarantee that we won't duplicate tasks.

This is the kind of process we are looking to create for the self-empowered Agile team.

Share

Maintenance plans in SQL Server 2008 failing on Windows Server 2008 R2

February 16th, 2010

I was having problems getting maintenance plans running.  I could see an error being logged by DCOM, but  when I went into component services to modify launch permissions everything was greyed out.  The solution is obvious, and can be found in the link below:

61738644-F196-11D0-9953-00C04FD919C1 Launch Permissions – Event 10016 on Windows Server 2008 R2 (SharePoint 2007 & SharePoint 2010) | Ulysses Ludwig's SharePoint blog.

Share

Quotations

February 4th, 2010

I just came across a good thread on Linked In of people's favourite Agile related quotations.  Here's my pick of the bunch:

 

The best is the enemy of the good.

 

Attributed on LinkedIn to Sir John Harvey-Jones, but it's actually Voltaire: "Le mieux est l'ennemi du bien."

Stop Starting, Start Finishing!
- Sterling Mortensen

If you want to build a ship, don't drum up the people to gather wood, divide the work and give orders. Instead, teach them to yearn for the vast and endless sea.
- Antoine De Saint-Exupery

In preparing for battle I have always found that plans are useless, but planning is indispensable.
- Dwight D. Eisenhower

It is a bad plan that admits of no modification.
- Publilius Syrus

Story tests verify "Building the right thing" vs. unit test that verify "Building the thing right".

Man who says ‘it cannot be done’ should not interrupt the man doing it.
- old Chinese proverb

It is not the strongest of the species that survives, nor the most intelligent, but the one most responsive to change.
- Charles Darwin

Here is Edward Bear, coming downstairs now, bump, bump, bump, on the back of his head. It is, as far as he knows, the only way of coming downstairs, but sometimes he feels that there really is another way, if only he could stop bumping for a moment and think of it. And then he feels that perhaps there isn't.
- A. A. Milne 

The biggest problem with communication is the illusion it has occurred.
- Michael James

Share

Effective Software Development – How to Compare Elephant Herds

February 3rd, 2010

It’s funny because it’s true…

effective software development.

Share

Pex – Some Early Thoughts

February 2nd, 2010

I've been looking recently at Pex, Microsoft's automated white box testing software. There's basically 4 parts to Pex:

  1. A framework for writing parameterised unit tests.
  2. An explorer, for finding boundary conditions in code.
  3. Suggestions of preconditions that should be added to methods.
  4. Moles – a way of stubbing even static properties and methods (such as DateTime.Now).

Parameterised Unit Tests (PUT)

When manually writing unit tests, we often end up with blocks of tests that are essentially the same in concept, but with different input/output combinations.  For example, an addition routine might have tests for different combination of negative and positive numbers.  Pex creates its tests a parameterized tests.  There is a template test, and underneath that an instance of each test value.

The templates are placed in a source file and look like normal unit tests.  The parameterised versions are stored underneath in a .g.cs file.  These files are not intended to be edited and are created automatically by the Pex explorer.

You can also write your own PUTs.  More on this later…

The Explorer

The 'white box' part of Pex refers to the explorer.  This essentially looks at all the possible paths through a piece of code and generates a test for each. Let's look at this piece of code:

public int Add(int x, int y)
{
    return x + y;
}

If we run Pex on this, we get the following test:

[TestMethod]
[PexGeneratedBy(typeof(CalculatorTest))]
public void Add01()
{
    int i;
    Calculator s0 = new Calculator();
    i = this.Add(s0, 0, 0);
    Assert.AreEqual<int>(0, i);
    Assert.IsNotNull((object)s0);
}

Actually there's a bit more to it – but this shows the basic details.  As we can see, it's a fairly dull test.  in particular Pex hasn't added any code to see if the result of the operation has overflowed. On the other hand let's see what it does if there's a bit more going on in the method:

public int Fibonacci(int n)
{
    if (n < 0)
    {
        throw new ArgumentOutOfRangeException("n");
    }

    if (n == 0)
    {
        return 0;
    }

    if (n == 1)
    {
        return 1;
    }

    return Fibonacci(n - 2) + Fibonacci(n - 1);
}

This is an (admiteddly rubbish) implementation of Fibonacci. It's more interesting that Add because there's more paths through it. This time when we run Pex we get:

[TestMethod]
[PexGeneratedBy(typeof(CalculatorTest))]
public void Fibonacci01()
{
    int i;
    Calculator s0 = new Calculator();
    i = this.Fibonacci(s0, 0);
    Assert.AreEqual<int>(0, i);
    Assert.IsNotNull((object)s0);
}

[TestMethod]
[PexGeneratedBy(typeof(CalculatorTest))]
public void Fibonacci02()
{
    int i;
    Calculator s0 = new Calculator();
    i = this.Fibonacci(s0, 1);
    Assert.AreEqual<int>(1, i);
    Assert.IsNotNull((object)s0);
}

[TestMethod]
[PexGeneratedBy(typeof(CalculatorTest))]
public void Fibonacci03()
{
    int i;
    Calculator s0 = new Calculator();
    i = this.Fibonacci(s0, 2);
    Assert.AreEqual<int>(1, i);
    Assert.IsNotNull((object)s0);
}

[TestMethod]
[PexGeneratedBy(typeof(CalculatorTest))]
[ExpectedException(typeof(ArgumentOutOfRangeException))]
public void Fibonacci04()
{
    int i;
    Calculator s0 = new Calculator();
    i = this.Fibonacci(s0, int.MinValue);
}

[TestMethod]
[PexGeneratedBy(typeof(CalculatorTest))]
public void Fibonacci05()
{
    int i;
    Calculator s0 = new Calculator();
    i = this.Fibonacci(s0, 14);
    Assert.AreEqual<int>(377, i);
    Assert.IsNotNull((object)s0);
} 

So Pex has created a test case for each path through the program.

Suggestions

When passing reference types to a method, Pex will realise that the value could be null.  For all such methods it will suggest the a pre-condition is added.  There's also a button that will get Pex to automatically insert the pre-condition into the code for you.  This saves a bit of time, but isn't a huge win.  That said Pex does understand code contracts so there may be bigger wins to be had here.

Moles

Pex also contains a mocking framework called Moles.  Unlike most mocking frameworks, Moles do their work at runtime level (like Isolator) and consequently you can use them to mock static properties.  Consider this code:

public void Y2kBug()
{
    if (DateTime.Now == new DateTime(1999, 12, 31))
    {
        throw new InvalidProgramException("Arrgghhh!!!!");
    }
} 

We'd like to unit test this, and we don't want to have to change the system clock to do so.  Unfortunately, DateTime.Now is static so the likes of Rhino Mocks and MoQ can't help.  With Pex Moles we can do the following:

[TestMethod]
[ExpectedException(typeof(InvalidProgramException))]
[HostType("Moles")]
public void Y2kBugTest()
{
    MDateTime.NowGet = () => new DateTime(1999, 12, 31);

    Y2k target = new Y2k();
    target.Y2kBug();
} 

We have generated Moles for mscorlib (by choosing Add New Item -> Pex Moles) in Visual Studio.  This creates a mole for each mscorlib type in the Moles namespace with the M prefix.  We then tell the mole to return the value we ant in the unit test (note that we supply a delegate not a value, and that properties are a Put and a Get mole).  By specifying the HostType attribute for our test, we cause the unit test runner to route the code trhough a mole supplying the value we want.

See Nikolai Tellman's video for more on this at: http://channel9.msdn.com/posts/Peli/Moles-Replace-any-NET-method-with-a-delegate/.

 

Share