Sunday, December 20, 2009

Notes on Pragmatic Unit Testing

Andy Hunt's book on Pragmatic Unit Testing is a good resource and should be on the bookshelf of every .Net developer.  I took a few notes while going through the book...

What to Test? Use Right BICEP method.

Right: Are the results right?
B: Are all the Boundary conditions correct?
I: Can we check Inverse relationships?
C: Can we Cross-check results using other means?
E: Can we force Error conditions to happen?
P: Are Performance characteristics within bounds?

Are the results right?
• We must validate method results and verify that the code ran correctly?
• Consider using data files for testing larger amounts of data.
• Use test classes/methods to prove the existing code is right.

Boundary Conditions
• Test the boundaries of code inputs using extreme data.
• Try to break the code and/or ensure data validation using garbage data that seems insane.
• Test for duplicates, data sequence, and security holes
• CORRECT (Conformance, Ordering, Range, Reference, Existence, Cardinality, Time)…more later

Check Inverse Relationships
• Work your methods backwards.
• Execute cycle of: 1) start with original data, 2) Inject Test Data, 3) Inverse new test data back to original data using test(s).

Cross-Check using Other Means
• Create a system of checks and balances by having test methods cross-check one another.
• Explicitly using different code to achieve the same results.

Force Error Conditions
• Create real-world scenarios by forcing errors to occur….creating negative tests.
• Some sample environmental scenarios include network availability, insufficient permissions, not enough disk space, overloaded CPU, etc.

Friday, May 01, 2009

Waltzing with Bears: Managing Risk on Software Projects

I found this to be an interesting read. It has made me think a little more about the potential risks that are associated with developing software and how to go about managing those risks.

Sunday, March 01, 2009

Passing Lists in SQL Server 2005

DECLARE @productIds xml

SET @productIds ='3615'

FROM @productIds.nodes('/Products/id') as ParamValues(ID)

Wednesday, February 18, 2009

Hierarchical vs Linear Workflow

Several of the applications that we've built or are currently working on in the OSS group involve the processing of workflow in some form. If you peruse the Web you'll find there are a variety of types such as "activity-based" or "content-driven". Microsoft Windows Workflow Foundation supports two types: "Sequential" and "State Machine" ( There is enough material out there though to make your head spin. Being that I'm not an authority on the subject I thought I'd explain in a simple-to-understand format the two types that we've used.

Hierarchical: workflow events are fired one at a time and they operate in a very sequential waits on the other. Example: I fill out a form and submit it to my boss for approval. Until he approves or denies the request, the entire transaction is in a holding state. Once he approves it, it then gets submitted to his boss. If he denies the request, it comes back to me. After all approvals have been gathered, the transaction is considered complete.

Linear: here workflow events all fire off on different threads (asynchronously) and are independent of one another. They must all be completed though before the transaction can be considered complete. Example: I put in a request to get a widget ordered. This order requires the participation of four different groups to perform an action. So, requests are sent to all four groups and they all complete their task independent of one another. Once all four are completed, the widget can be processed.

Hopefully those two approaches make sense. If you have more to add to this topic, I welcome your feedback.

Friday, February 13, 2009


Someone sent me this story via email and I just had to share it...

At a fundraising dinner for a school that serves children with learning disabilities, the father of one of the students delivered a speech that would never be forgotten by all who attended. After extolling the school and its dedicated staff, he offered a question:

'When not interfered with by outside influences, everything nature does, is done with perfection. Yet my son, Shay, cannot learn things as other children do. He cannot understand things as other children do. Where is the natural order of things in my son?'

The audience was stilled by the query.

The father continued. 'I believe that when a child like Shay, who was mentally and physically disabled comes into the world, an opportunity to realize true human nature presents itself, and it comes in the way other people treat that child.'

Then he told the following story:

Shay and I had walked past a park where some boys Shay knew were playing baseball. Shay asked, 'Do you think they'll let me play?' I knew that most of the boys would not want someone like Shay on their team, but as a father I also understood that if my son were allowed to play, it would give him a much-needed sense of belonging and some confidence to be accepted by others in spite of his handicaps.

I approached one of the boys on the field and asked (not expecting much) if Shay could play. The boy looked around for guidance and said, 'We're losing by six runs and the game is in the eighth inning. I guess he can be on our team and we'll try to put him in to bat in the ninth inning.'

Shay struggled over to the team's bench and, with a broad smile, put on a team shirt. I watched with a small tear in my eye and warmth in my heart. The boys saw my joy at my son being accepted. In the bottom of the eighth inning, Shay's team scored a few runs but was still behind by three.

In the top of the ninth inning, Shay put on a glove and played in the right field. Even though no hits came his way, he was obviously ecstatic just to be in the game and on the field, grinning from ear to ear as I waved to him from the stands.

In the bottom of the ninth inning, Shay's team scored again.

Now, with two outs and the bases loaded, the potential winning run was on base and Shay was scheduled to be next at bat.

At this juncture, do they let Shay bat and give away their chance to win the game? Surprisingly, Shay was given the bat. Everyone knew that a hit was all but impossible because Shay didn't even know how to hold the bat properly, much less connect with the ball. However, as Shay stepped up to the Plate, the pitcher, recognizing that the other team was putting winning aside for this moment in Shay's life, moved in a few steps to lob the ball in softly so Shay could at least make contact.

The first pitch came and Shay swung clumsily and missed.

The pitcher again took a few steps forward to toss the ball softly towards Shay. As the pitch came in, Shay swung at the ball and hit a slow ground ball right back to the pitcher.

The game would now be over. The pitcher picked up the soft grounder and could have easily thrown the ball to the first baseman. Shay would have been out and that would have been the end of the game. Instead, the pitcher threw the ball right over the first baseman's head, out of reach of all team mates. Everyone from the stands and both teams started yelling, 'Shay, run to first! Run to first!' Never in his life had Shay ever run that far, but he made it to first base.

He scampered down the baseline, wide-eyed and startled.

Everyone yelled, 'Run to second, run to second!' Catching his breath, Shay awkwardly ran towards second, gleaming and struggling to make it to the base. By the time Shay rounded towards second base, the right fielder had the ball . The smallest guy on their team who now had his first chance to be the hero for his team. He could have thrown the ball to the second-baseman for the tag, but he understood the pitcher's intentions so he, too, intentionally threw the ball high and far over the third-baseman's head. Shay ran toward third base deliriously as the runners ahead of him circled the bases toward home.

All were screaming, 'Shay, Shay, Shay, all the Way Shay'

Shay reached third base because the opposing shortstop ran to help him by turning him in the direction of third base, and shouted, 'Run to third! Shay, run to third!' As Shay rounded third, the boys from both teams, and the spectators, were on their feet screaming, 'Shay, run home! Run home!' Shay ran to home, stepped on the plate, and was cheered as the hero who hit the grand slam and won the game for his team.

'That day', said the father softly with tears now rolling down his face, 'the boys from both teams helped bring a piece of true love and humanity into this world'.

Shay didn't make it to another summer. He died that winter, having never forgotten being the hero and making me so happy, and coming home and seeing his Mother tearfully embrace her little hero of the day!

Wednesday, February 11, 2009

Cohesion and Coupling

Every seasoned object-oriented developer should be familiar with these coding principles. Sometimes we forget though to implement them in the code that we write which leads to future refactoring. This article is a good reminder of these design and architecture patterns, and it provides some pretty good examples.

Sunday, February 01, 2009

URL ReWrite

void Application_BeginRequest(object sender, EventArgs e)


System.Web.HttpContext httpContext = HttpContext.Current;

String currentURL = httpContext.Request.Path.ToLower();

string processPath =currentURL.Substring(httpContext.Request.ApplicationPath.Length).TrimStart('/').ToLower();

//Creates th

string physicalPath = httpContext.Server.MapPath(

currentURL.Substring(currentURL.LastIndexOf("/") + 1));

//checks to see if the file does not exsists.

if (!System.IO.File.Exists(physicalPath))


string queryString =httpContext.Request.ServerVariables["QUERY_STRING"];

string defaultPage = "~/PageViewer.aspx?process=";

if (processPath.EndsWith(".aspx"))

processPath = processPath.Substring(0, processPath.Length - ".aspx".Length);

// Rewrites the path

httpContext.RewritePath(defaultPage + processPath + "&" + queryString);



Peopleware: Productive Projects and Teams

This is one of the best books that I've read in a while on People Management. I would recommend it to all Development and Project Managers...heck, all managers in general.

Thursday, January 22, 2009

Show screens early

One of the principles of Agile Development (via the Manifesto - is to deliver working software frequently. One of the main ways we do this within the OSS development group is to get screens out there to our users early. Even if the screens don't do a whole lot, the functionality that they do contain has been tested and works.

Throughout the development of an application we're continuously pushing out features in small iterations to our customers. Even though the product is not fully "baked" it allows them to see visual progress, begin working with the product, and even provide testing and feedback.

So far it has produced great results. Our customers know exactly what they're getting, they've had interactive collaboration with us throughout the development effort, and the end result is a custom technology solution that meets the business need.

Wednesday, January 07, 2009

SQL Tuning

A while back one of the guys on my team recommended to me SQL Tuning as a fabulous read. I also endorse it as a book that should be a part of every SQL Developer's library. Note: it is not a light weekend read, but it will get you thinking about how you go about writing your SQL Statements going forward.