Test driven development – problems when developers opt out

March 3rd, 2010

This post was originally published here by Valtech UK consultant Andrew Rendell.

We have two major classifications of automated test in common use for test driven development (TDD):
  • Acceptance tests which execute against the application in its fully deployed state.
  • Unit tests which typically target a single class and are executed without instantiating a Spring container.
The acceptance tests are written in language which should make them accessible outside of the development team. They are used to measure completeness, automatically test environments and provide regression tests. Their usefulness is widely accepted across the team and they tend to be very longevid, i.e. tests that were written a year ago against a particular API are relevant today and will continue to be relevant as long as that API is supported in production. The unit tests are written by developers and will almost certainly never be read by anybody other than the developers or possibly the technical leads. I program using TDD as I find it a natural way to construct software. I personally find that the tests are most useful as I am writing the code, like scaffolding. Once the code is stablized the tests still have a use but are no longer as critical. A refactoring of the application in some future sprint may see those tests be heavily amended or retired. They are not as longevid as the acceptance tests.

I have been reflecting on the usefulness and investment in test code for as long as I had been doing TDD. I had come to a conclusion that whilst acceptance tests are non-negotiable on projects where I have delivery responsibility, perhaps unit tests for TDD are not mandatory in certain situations. I have worked with several developers who are very very good and simply do not see the value in TDD as it is contrary to their own, very effective, development practices. I know in my team right now a couple of the very best developers do not use TDD the way everybody else does. Education and peer pressure has had no effect. They are delivering high quality code as quickly as anybody else. Its hard to force them to do differently - especially when some of them pay lip service to TDD and do have a high test coverage count. I know that they write those tests after they write their code.

In the last few weeks I came across a couple of concrete examples where TDD could have helped those developers deliver better code. In the future I will try and use these examples to persuade others to modify their practice

1. Too many calls to downstream service.

The application in question has a mechanism for determining identity of a client through some network services. Those network services are quite expensive to call. The application endeavors to call them infrequently as is safe and cache identity when is is resolved. We recently found a defect where one particular end point in the application was mistakenly making a call to the identity services. It was not that the developer had made a call in error, it was that the class inheritance structure effectively defaulted to making the call so did so without the developer realizing. The identity returned was never used. I suspect that this code was not built using TDD. If it had been then the developer would have mocked out the identity service (it was a dependency of the class under construction) but would not have set an expectation that the identity service would not have been called. The use of mocks not only to specify what your code should be calling but what it should not be calling is extremely useful. It encourages that top down (from the entry point into the system) approach where you build what you need when you need it.

Its likely that the defect would never have been introduced had the developer been using TDD. As it is we have a application which is making a large number (and it is a large number) of irrelevant calls to a contentious resource. We now have to schedule a patch to production.

Coincidentally, there was an acceptance test for this service, which was passing. This highlights a deficiency in our acceptance tests we have to live with. They test the 'what' but not the 'how'. The tests were running against a fully deployed application which had downstream services running in stub mode. The test proved that functionally the correct result was returned but it had no way of detecting that an additional spurious call to another service had been made during the process.

2. Incorrect error handling

In a recent refactoring exercise we came across a piece of code which expected a class it was calling to through an exception whenever it had an error processing a request. The error recovery in the code in question was quite elaborate and important. Unfortunately, the class being called never threw an exception in the scenarios in question. It had a status object it returned which indicated if corrective action needed to be taken. (It was designed to be used in conjunction with asynchronous message queues where throwing an exception would have introduced unnecessary complexity). The developer could have easily used mock objects and set an expectation that the exception would be thrown and the problem would have remained. But, if TDD was being used and the developer was working top down then the expected behavior of the mocks would have guided the implementation of downstream classes. Nothing is foolproof but I think this manner of working should have caught this quite serious error.

More subjective problems

I have also noted two other potential consequences of having some developers opt out of TDD. I do note that some developers on the team produce code that is more complex than others. It is fine from a cyclomatic complexity perspective but when you try and understand what it is doing you find yourself with a higher WTF count than you would expect. I think (again this is subjective, I have not gathered any empirical evidence) that a lot of the complexity comes from a lack of cohesion in the code. Logic is spread around in a way which made sense to the original developer as they had internalized all the classes concerned. That logic is not obvious to a new pair of eyes. If you are using TDD then this encourages cohesion in classes because it focuses the mind on what the class is responsible for before the developer has to worry about how it delivers those responsibilities.

This is a very subjective point and I would happily agree that several of the team members who do use TDD occasionally produce nasty code. My gut feeling however, is that it happens less often.

One final problem with some of the high flyers not using TDD is that bad practices tend to propagate through the team just as quickly as good ones. I have caught a couple of new joiners following a bad example or simply not using TDD becuase the developer they look to as a mentor is not evangelizing about the technique because they themselves do not buy into the practice. This is a shame as those new joiners often have a greater need of the rigor that TDD imposes than the more experienced developers.

Software release management – Anti-pattern: The release vehicle

February 22nd, 2010

This post was originally published here by Valtech UK consultant Andrew Rendell.

At my current client site you cannot get a piece of compiled code into production unless you can find an appropriate 'release vehicle', i.e. a planned high ceremony release of the component which has been officially prioritised, scheduled and funded. (Note: The same does not apply to non-compiled code such as JSPs or XML templates containing complex XPath expressions).

Somebody very clever, who probably had a beard (Grady Booch?), once said that "Regular releases into production are the lifeblood of the software development process.". I agree. My current client also seems to be in agreement but cannot extract themselves from the constraints their existing processes.

The client in question has a successful agile adoption. Walking round the development teams you see task boards, burn downs and SCRUM meetings. Go to a management meeting and you'll hear them talk about two week iterations and the importance of continuous integration. At a strategic level, the organisation (which is very large) is still waterfall orientated. This has implications for the way in which work is financed. Funds for the development, testing and deployment of a certain application are released on waterfall inspired milestones. This, in conjunction with a legacy of long development cycles has led the this 'release vehicle' anti-pattern.

The organisation has an unwillingness to make a deployment of a component into production unless there is named and funded change request which covers its release. Activities within development, possibly funded internally as 'business as usual' do not have such CRs. Therefore, a development activity such as refactoring for technical debt reduction or improving performance might get engineering buy in but will not get released into production until some CR happens to touch the same application.

It is common to see refactorings made which then sit in source control for literally months as they wait for an excuse to go live. Medium to low priority defects or useful CRs which lack very high prioritisation from marketing never get executed because the programme manager does not have a release identified for the change.

The application suite can appear inert to external parties as it takes a considerable period for changes to make it through the full release cycle. This erodes confidence. If I was a product owner and saw that a team was taking six months to execute my minor change I am not going to be inclined to believe that the same team can turn around my big important changes quickly. I am going to be looking for other mechanisms to get my changes into production and earning money quickly. Once I find a route that works I am going to keep using it.

Why do people like the release vehicle?
  • It is the way the whole software lifecycle as exposed to the rest of the organisation works. The QA team don't test a component unless they have funding from marketing. Marketing won't be paying for something that has no role in a prioritised proposition. The Operations team won't support the deployment actives for our component if they don't have the cash from the same marketing team.
  • It looks like it is easier to manage for PMs. Releases (because they are infrequent) are a big deal, involve lots of noise, planning, disruption to everyday working pattern.
  • It reduces the infrastructure costs. It costs resource to make a release unless every aspect including testing and operational deployment is fully automated (and even then there is potential cost, dealing with failures etc.). It costs resource to automate a manual build process. Engineers appreciate that fully automated build processes are a priority because in the end they reduce costs and increase agility. It is that age old problem of trying to convince not just the build team, but the build team's manager and the build team's manager's manager that it is worth diverting resource in the short term to fix a problem in order to make a saving in the long term.
** This is a symptom of our strategic failure to get agile adopted beyond the development group. Until we do so, we will continue to hit these sort of issues. What we should do instead:

We should schedule frequent (bi-weekly, ideally more frequent) updates in production from the trunk of source control for every component. We should not need an excuse for a release. The release process should be as cheap as possible, i.e. automated build, regression test, deployment and smoke test. The code in the trunk is supposed to always be production ready and the automated tests should keep it that way.

If we achieve this we should:

  • Reduce complexity in branch management (no merging changes made months ago).
  • Avoid a massive delay between development and deployment which is not cost effective and makes support very hard.
  • Increase our perceived agility and responsiveness.
  • Enable refactoring to improve non-functionals (stability, latency, dependency versions, capacity).
  • Prevent a release from being a 'special occasion' which requires significant service management ceremony.
If you release all the time everybody knows how to release. If you release twice a year every release involves re-education of the teams involved on deployment, load testing, merging etc.. etc. This increases the cost and risk that it fails.

Note: Having frequent, regular, low ceremony releases is greatly eased by having a fully automated build and deploy process but you can have one without the other. As stated above, having such a build process makes regular deployments to production cost effective but is an enabler rather than the justification for this change to working practice.

Prioritising stories within a sprint?

February 10th, 2010

This post was originally published here by Valtech UK consultant David Draper.

In a recent post Karl Scotland drew my attention to this post by Craig Dickson on Agile DZone. Karl and Craig differ on their approach (when working with Scrum) to prioritisation of stories by the product owner within a sprint.

Craig has a valid concern that we might loose sight of our Sprint commitment if we have high and low priorities within the sprint, what if we don’t get to low priority stuff, well it was only low priority! He also raises concern over the degree to which the team is empowered if the Product Owner specifies a priority order for within the sprint.

By contrast Karl has his focus firmly on WiP (work in process), and through that lens the sprint is secondary to a focus on flow, prioritisation will encourage the team to focus on flow. I have some sympathy with this point of view.

As is so often the case I feel that I fall between these two camps.

  • I believe in an empowered team who pull from the backlog
  • I believe in the team making a commitment to a sprint scope
  • I believe in the team self-organising around moving that scope through to releasable product

But, there is always a but, these things don’t preclude prioritisation.

We pull from the backlog in order to take into account team capacity / capability. We pull in the correct amount of work with an appropriate profile e.g. not all database heavy wok if we have limited DBA capability. This means that the team may not always pull items from the very top of the backlog. The team commitment is an open honest expectation that this work can and will be achieved by the end of the sprint. We don’t sack or punish the team if a commitment is missed, in fact it could be argued that the commitment should be missed from time to time due to special causes. We don’t want to pad sprint plans with high amounts of contingency. Finally the team self-organise around achieving the goal.

When I introduce teams to Scrum I recommend working against a prioritised sprint backlog. Why? The prioritisation helps in a number of ways:

  • The team is challenged to find ways to move stories to Done faster
  • The team is encouraged to collaborate and help each other out in favour of picking new tasks
  • We bind people to tasks late, prioritisation helps them select tasks according to team need rather than specialisation
  • Where a sprint commitment is missed we loose 1 story rather than a bit from each story.

So in short, I agree with much of what Craig has said, it should not be the responsibility of the PO to prioritise the sprint backlog. However, I do see the need for the team and PO to collaborate in order to ensure that the needs of the business do not take second place to the needs of the process. I also share much of Karl’s motivation with respect to limiting WiP and achieving Flow.

For me prioritisation is a strategy that a team can use to self organise around a given sprint commitment. It encourages collaboration and mitigates risk, how can that be bad?

Tale of two SCRUM stand ups

February 2nd, 2010

This post was originally published here by Valtech UK consultant Andrew Rendell.

I walked past two teams doing their daily SCRUM standup today. Both teams claim to be agile. I didn't join in (even as a chicken) but just observed for a minute or so.

The first team was sitting down in a breakout area. Their body language spoke volumes. There was not one single participant maintaining eye contact with anybody else. Two people were playing on their phones. One developer had his head in his hands. Most had bored expressions. The team leader who is also the SCRUM master was the only person who spoke for the entire time I watched.

The second team was stood in a space near their desks. They were gathered round a task board which appeared to be up to date and the focus of several of the individual's updates. One person spoke at a time. Almost everybody appeared to be paying attention to whomever was speaking. Most updates were short and concise. A couple rambled on.

Other than both teams calling their meeting a SCRUM I could see no similarities.

As our agile adoption has spread beyond the original teams I suppose it is inevitable that as the experience gets spread a little thinner that people will simply label their existing activities with agile sounding names. Often we have no clear remit in those teams to supply a mentor and to try offer advice would result in rebuttal as team leaders guard their territory. Does this matter? Is there a risk that these teams who are not practicing agile correctly will diminish and discredit agile in the eyes of our programme managers? This is sounding a bit like an excuse for an Agile Inquisition going round checking that no team is using Agile's name in vain. This cannot be a good thing either.

Reviewing a project initiation

January 28th, 2010

This post was originally published here by Valtech UK consultant David Draper.

I was recently asked to help a client kick-off development of a new product. This was to be their first “agile” project so the kick-off had to set the scene for the collaborative development approach that was to follow.

I used a variety of tools and techniques to bring the project to life. As is usually the case, some worked better than others so I thought I’d review the approach and describe some of the issues and possible reasons.

The agenda for the day was:

  1. Review project vision and goals
  2. Establish key priorities and concerns
  3. Establish candidate releasable chunks
  4. Decide what to do first

Attendees included the development team, development management and business sponsors.

Project Vision

After some general discussion about the product we set about defining the Vision. The group were split into smaller groups each mixing development and business folk. Each team was asked to come up with an elevator pitch for the project of the form:

For __Customer__ who __has some need__
the __product name__ is a __product type__
that __will provide some benefit__
unlike __competing products__
out product will __key differentiator__.

In reviewing each groups proposed vision statement we settled on a single elevator pitch that embodied the purpose of the project and began to focus the team on what might be important.

Project goals

To further cement the way in which the product could be judged a success we went on to identify candidate goals. These included some consideration of how we might measure success.

These two exercises were received with some enthusiasm as the sub teams collaborated over achieving an accurate representation of the product. The need to measure outcomes causes business sponsors to work with those who were more technically minded in order to achieve measures that were specific, measurable and representative of the desired outcome.

Goals in this example included areas such as customer and sales force satisfaction as well as specific operational cost reduction goals.

Sliders

This is a technique that I picked up from Rob Thomsett’s Radical Project Management. I have used it to great effect in the past where trade-off was a critical demand of the project.

The sliders technique works by selecting a set of traits that could be considered to be in tension. These are represented as sliders that can be fully on, fully off or anywhere in-between. The stakeholders and team can discuss the implications of various slider positions. For example when considering cost and budget to be fixed we may choose to allow for some flexibility in scope in order to ensure quality.

Thomsett uses these seven measures of success; satisfied stakeholders, meet requirements, meet agreed budget, deliver on time, meet quality requirements, satisfy the team. I have used the same technique with other measures such as maintainability, time to market etc.

This technique was less well received than the previous two. While the discussion that was provoked was valuable some members of the group were unhappy with the somewhat arbitrary nature of the measures. One sponsor suggested that he felt that he was having to trade off his goals before even the project has started.

I believe that this early trade-off is a valid concern and it came up more than a couple of times throughout the project. When we apply agile principles to product development we look for small meaningful increments. This can be uncomfortable where a sponsor has internalised a grand vision.

Establishing releasable chunks

This exercise starts with the suggestion that it is good for the project to reach a releasable state early. We begin by identifying a set of capabilities of the system. These are grouped based on cohesion. I use the notion of Minimal Marketable Features to focus on achieving small releasable increments. We begin to prioritise these and work to make the first chunk as small as is reasonable in order to achieve marketability.

This was the most valuable and effective part of the day. The notion of MMF was used extensively through the project with the business sponsor often stating that a feature was “important but not necessary for this MMF”. Further, the focus on marketability places some focus on needs that can often be deferred such as security testing, performance testing and help facilities.

The following day would include beginning to identify the User Stories that would be necessary in order to achieve MMF 1.

Lessons learnt

In reflecting on this exercise there are things I would do the same and things I would consider doing differently. The initial Vision and Goals exercise was well worth while. While I know that the success sliders approach can be useful I may not have used that technique in this particular context.

A technique that I chose not to use, on reflection, would have been a good choice. As a part of the identification of releasable chunks we should have begun to identify those personas that we could address and how they related to different feature sets. I believe that this would have increased our focus on specific features and aspects of features.

We live and learn :)

Thanks for taking part in my mini retrospective on this workshop, I hope it can be of use to others. Please do feel free to ask questions of make comments below.

Technorati Tags:

Theory of constraints for beginners

January 25th, 2010

This post was originally published here by Valtech UK consultant David Draper.

Take-away #3 from David Anderson’s Kanban Coaching workshop.

A discussion of Kanban can only go on for so long before the subject of the Theory of Constraints comes up. In this post I’ll try to explain just enough to show this connection.

Theory of Constraints (TOC) is a large subject that I was first introduced to some time ago by Pascal Van Cauwenberghe and his explanation of the 5 focusing steps for process improvement. Since then I’ve seen TOC pop up at a few Agile conferences. The most notable aspects that tend to be discussed are the 5 focusing steps mentioned earlier and the TOC thinking tools. The Thinking tools offer techniques for root cause analysis, problems solving, conflict resolution and planning. While there have been a number of books explaining these techniques the source material is a set of novels written by Eliyahu Goldratt the first being The Goal: A Process of Ongoing Improvement.

David’s first book (Agile Management for Software Engineering) was focused on applying TOC in a software engineering context so I guess it’s not surprising that he wold choose to spend a little time explaining the connection between Kanban and TOC.

At this stage I should say that where David has applied TOC he has subsequently realised that a Kanban approach would have led to an equivalent result and is a conceptually more simple approach.

The areas of TOC that David chose to focus on were the classification of bottlenecks and the application of Goldratt’s 5 focusing steps.

  1. Identify the bottleneck
  2. Decide how to exploit the bottleneck
  3. Subordinate the system to the bottleneck
  4. Elevate the bottleneck
  5. Repeat

These steps carry with them a set of pre-suppositions.

  • We understand the goal of the system
  • A system has a single bottleneck that constrains it’s throughput
  • It is better to undertake changes that have no cost first i.e. improve utilisation of existing resources before adding resources

While for most types of system I am willing to hold with these pre-suppositions we should accept that while bottlenecks can move in a manufacturing context they are likely to move more quickly within a software context due to the greater degree of variability.

So, an example of applying these steps in a software development context might be;

Our goal is to construct, test and deploy software.
Our constraint is in system test, this is apparent due to a build up of software that has not been tested.
We identify exploit opportunities by considering where we loose test capacity e.g. recording timesheets. Since test is the bottleneck, time spent doing administration is directly reducing the output of the system.
We subordinate the system to the bottleneck by changing responsibilities e.g. PM to take on some administrative tasks from testers.

At this stage we return to assessing where the bottleneck is. If we run out of exploit / subordinate opportunities we may choose to elevate the constraint. This is where we consider adding resources, automation or training.

To close we should consider how a bottleneck might manifest it’s self in a system. Though others have suggested classifications for bottlenecks David’s approach is to consider 2 types.
Capacity constrained resource
Non-instantly available resource

For example compare a bridge with a ferry. A bridge has a fixed capacity, congestion occurs where too many cars attempt to cross. A car ferry will cause queues even where capacity is sufficient due to it’s non-instant availability.

Technorati Tags: ,

Using JIRA for Agile Project Management (without Green Hopper)

January 12th, 2010

Jira from Atlassian is a very popular issue tracking software and can be quite effectively used for Agile Project Management. Jira has a plugin (Green Hopper) that allows for creation of a backlog, iterations and tasks. However, with help from the free Mylyn plugin for Eclipse I was able to setup a Product Backlog and Iteration Backlogs.

For the User Stories in the product backlog I created two issue types (Epic & User Story). Story hierarchies can be represented using Jira Links.

For Iteration Backlog I created a version for each iteration and assigned the stories to that version/iteration. Each leaf story can then have Jira Sub-tasks to represent the tasks in a particular iteration. The Resolved state of the story is used to mark it complete and Colsed state is used to mark it as “accepted”. You can use Mylyn to see story hierarchies, also I found Mylyn to be a much more intuitive interface when working on Product and Iteration backlogs.

By Mashooq Badar.

Day CQ5 (CMS) and JBoss Portal (cont) : Application Portlet Discovery

December 10th, 2009

Click here.

How do you make applications portlets available to page authors in CQ5, so page authors can design/author the complete site without requiring application releases?

By Mashooq Badar.

Day CQ5 (CMS) and JBoss Portal (cont.): Synchronised Menus

December 9th, 2009

By Mashooq Badar. Click here.

The Portal Server has it’s own means of generating menus and CQ5 has a different mechanism. How do you synchronise the two?

Day CQ5 (CMS) and JBoss Portal

December 8th, 2009

Valtech consultant Mashooq Badar writes on managing CMS and web applications here.

In this blog we look at the challenges for a CMS in managing a site that has embedded web applications – using examples of JBoss Portal and CQ5 CMS from Day.