Wednesday, April 18, 2007

Unit Testing Expected Exception

I have seen and implemented a few different patterns to unit test expected exceptions. This was one that I saw the other day that seems to be the pinnacle pattern to unit test an expected exception.

The key aspects of it are:
• Declaration of a variable scoped to the entire method to hold a reference to an exception (Dim theExpectedException As ArgumentNullException)
• Catching the exception @ the most granular level that it HAS to be the expected exception, by using the correct exception type (ex As ArgumentNullException) and the when clause (When ex.ParamName = "lab").
• Asserting on the condition that the exception IsNotNull proves it was thrown and caught in the method.


Sub NewILabAdornmentsNegativeILabNull()

Dim lab As ILab = Nothing
Dim adornments As IDisplayLine.LabAdornmentStrings = None
Dim target As IDisplayLine
Dim theExpectedException As ArgumentNullException = Nothing

Try
target = Factory.DisplayLine(lab, adornments)
Catch ex As ArgumentNullException When ex.ParamName = "lab"
theExpectedException = ex
End Try

Assert.IsNotNull(theExpectedException, "Proves Factory.DisplayLine(ILab,LabAdornmentStrings) throws an ArgumentNullException exception when passed a null lab.")
End Sub

What Macallan @ Old Homestead Should I Get

I am going to the Old Homestead next weekend. I am committing to an appx $150 shot of Macallan. Any suggestions??? I had the 1968 last time and really enjoyed the caramel tones.

Tuesday, April 17, 2007

TFVC - Check Out - Check In - Lock

So, we're about to make the leap from VSS to TFVC. We've got 60 developers. How many times will we lose source code due to someone doing a bad merge?

Anyone else recently gone thru this?

Monday, April 16, 2007

VSS History for added files in CCNet

Discovered late last week that when using ccnet components to query VSS for changes, that added files do not have a full path. They only have a 'folder name\file name' path. All parent folders are missing from the path.

Has anyone else looked into how to fix this for ccnet?

Friday, April 13, 2007

CI Factory

Made my second submission to CI Factory today.

Not comfortable with the process yet, but it was my second OSS submission.

Writing Unit Tests For TDD Backwards

Today, co-worker asked me how to write a unit test.

I basically explained to him that we write them backwards:


1. Write the test’s Description using “Proves correctly …”
2. Write your Assert(s) – Each needs to describe its own “Proves…” and that “Proves..” must support the overarching “Proves…”
3. Write your Exectution – The SINGLE statement that invokes the target of the test
4. Write your Setup

When you do the above steps, everything becomes very focused and clear.