September 30, 2007
@ 01:23 PM

I recently posted a short blog on using TDD practices when working with Legacy code. In a comment to that post Mike Kelly raised a couple of questions/issues that I want to address.

Here is part of the comment Mike made:

One question I have, is how to apply atomic TDD methods, modules, to code that is not really designed for TDD?
For instance, if you had to support VB6, or COBOL, or some other language... not to mention scoping visibility...
I struggle at times just writing TDD code for my own code! I'd be interested to hear more on this topic...

TDD principles dictate that tests should be "Atomic", that is they should apply to a very granular area of code in the system under test. So how would we implement TDD in a legacy system especially one that TDD had never been used with before?

In a word, Mock Objects. Mocks become very valuable when you have to work with a system "at arms length" from the code. That being said, there are some issues with this approach. You are adding a layer of abstraction from the actual code under test, and if you are not careful you end up with test code that is too tightly coupled to the code you are trying to test which makes any refactoring difficult.

Mocks are not the end all be all by any means. In the .NET world it is actually fairly easy to add TDD support for languages like VB6 after the fact. Scope is certainly an issue. But since VB6 can call .NET assemblies via COM Interop you can fairly quickly put together a test class inside of the scope of a VB6 application. If there is any interest I can blog some examples on this with a project that I recently added TDD practices to.

I have not worked with any variant of COBOL since the early 80's when I worked on an IBM 360 system. So I can't comment directly on COBOL, but I would imagine Mocks would help here as well.

Next post, Mocks!

Cheers,

Robert Porter

Some resource links of interest on this topic.

Applying Test Driven Development to an existing application. - Eric Hexter's Blog

Test Driven Development, a Portable Methodology - Nancy Corbett

Why and When to Use Mock Objects

Jeremy D. Miller


 
Categories: Programming | TDD


Brad Wilson just posted some interesting new attribute usage information on xUnit.net here. And discusses an upcoming feature called [FreezeClock] which will solve an issue I have been having.

He explains [FreezeClock] this way:

Another one we'll do for CodePlex is one I call [FreezeClock], which uses our internal Clock class (a testable replacement for DateTime) which supports the concept of freezing the clock at a moment in time, and then unfreezing when the test is over. This is useful to ensure, for example, that some code under test is calling "Clock.Now", so that you can actually test the value they pushed in some arbitrary amount of time later by simply calling "Clock.Now" again. When we get around to doing that one, I'll make a blog post which shows the Clock class as well as our attribute.

There is another interesting tidbit, another extension called [AssumeIdentity]! Go read for yourself!

Cheers,

Robert Porter


 
Categories: TDD


September 26, 2007
@ 04:04 PM

First, let me be clear about what I mean by "Legacy" code. In most shops legacy refers to anything not currently under active development.   A program written a month/year ago for which development had legacyceased. At least this is the definition that I am dealing with for the purposes of this post.

We all know the feeling, something happens to cause a change to be made in an application or other component that has long been "just working". And now you have to wade in and get that crawly feeling of rummaging around in someone else's code.

The fears are common, and real, if you are unfamiliar with the code you are also unfamiliar with the original developers assumptions, the cross dependencies in the code base, even potentially external dependencies.

So you hesitate at each step, afraid to change anything for fear of introducing a bug, or outright breaking everything. Cause, you know, if you break it, you own it! Now and forever more.

FearOften the original developers are no longer easily reachable, either because they have been reassigned, moved on, left the building in a straight-jacket. For whatever reason when we as developers are required to delve into a "legacy" system it often brings a high level of tension along with it!

But it is something we all have to deal with from time to time. So how can we approach this task and minimize both the risk and the fear? In a word, TDD.

Test Driven Development is not just for shiny new development, it can be applied retroactively to existing code. And modifying a legacy application is the perfect time to introduce unit tests to an application that did not already have them.

If the code already had unit tests, and they are passing, you are way ahead of the game, but if not, adding them can be your salvation.  When I tackle a legacy project, at the very least I try and identify the portion of the code base I am going to be working with. Then I create a unit test module to test the existing code as is (and my assumptions about that code as well), and get them to pass before I change one line of existing code.

With that done, I can begin introducing changes with some degree of confidence that I am not going to *break* anything along the way, at least not without knowing about it. I begin my Red/Green/Refactor process until I have achieved the desired change, and all the tests are still passing.

This concept seems straightforward, at least to me, but for some reason most developers are reluctant to apply TDD concepts to projects that do not already have them. I am not sure why this is the case, but I know when I have done this I tend to sleep a lot better. Plus it adds real value for the next poor sucker that has to maintain this particular piece of legacy!

Cheers,

Robert Porter

Technorati Tags: , ,

 
Categories: Programming | TDD


September 25, 2007
@ 02:42 PM

In a word, MsiZap. A great utility I stumbled on while looking for some help getting rid of entries in my Add/Remove programs list that had issues or failures with uninstalling.

Here is the article on the utility and it's usage. It worked well for me, sharing now with you!

Cheers,

Robert Porter


 
Categories: Misc | Tools and Toys


September 25, 2007
@ 12:10 PM

Matt Blodgett posted an very timely (for me) on an issue with debugging web applications on Windows Vista. Read the full article on his site, but if you are having issues where VS2005 mysteriously leaves debug mode while you are sitting on a line of code this is your answer!

Cheers,

Robert Porter


 
Categories: .NET | ASP.NET | Programming | Visual Studio


I ran across a nice article by Mark Seemann on MSDN. It was published in the September 2007 issue of MSDN Magazine. In it he covers what he describes as the continuum relationship of Mocks, Dummies, Stubs, Spies and Fakes in Unit Testing.

The following diagram is from his article to illustrate the point:

Implementation Coverage

As you can see, each component has varying levels of implementation depending mostly on your needs etc. The article is worth a read!

Cheers,

Robert Porter


 
Categories: Programming | TDD | Agile


I have a Dell XPS M170 laptop that I love. And some time ago I upgraded it to Windows Vista Ultimate 32-Bit. It was a bit of an effort to get everything working, but for the most part I was able to find Vista drivers for everything.

However I did experience one issue. The integrated speakers worked fine, but the external headphone/speaker jack stopped working. On a lark last night, I checked Dells drivers and downloads site and lo and behold there are now new Vista ready drivers for the whole system.

I downloaded and installed them and everything is again working, including my headphones!

Lesson learned, periodically check with the hardware Vendor for new and updated drivers. It will save you some heartburn on occasion.


 
Categories: Hardware


September 23, 2007
@ 06:55 PM

I recently updated this blog to the latest stable 2.x build of dasBlog and I also changed the default Theme to the one you see now.

There were some hiccups and a few tense moments when I noticed that several things that I thought should work did not. Turned out that the issues were with IE7/Vista caching and had little to nothing to do with dasBlog.

That being said, if you notice anything unusual please let me know!

Cheers,

Robert Porter


 
Categories: dasBlog


September 23, 2007
@ 10:39 AM

I would have to say that I have become a convert to TDD concepts. I have used NUnit, and mbUnit testing frameworks to varying degrees for some time. Now I use them daily and am working to increase my coverage in all my projects.

Since I primarily develop in the .NET Framework I have particular interest in the unit testing frameworks available in that environment. As I mentioned in a previous post I have currently settled on mbUnit as my unit testing framework.

xUnit is a new framework developed by, among others, James Newkirk and Brad Wilson. James was one of the original authors of NUnit and is now a Microsoft employee. Brad Wilson also works for Microsoft. Together they have created what looks to be a very well thought out testing framework.

xUnit is currently being hosted on CodePlex and is distributed under Microsofts Permissive License (The borgs version of Open Source).

The framework has already been integrated with TestDriven.NET, and has it's own console runner, but no GUI runner yet.

Roy Osherove has a series of posts about his view on xUnit, and both James and Brad have blogged about it as well. The first post of interest to me was this one, then check this one.

After reading all the various points of view on this topic here is what my take away is so far. xUnit is a conscious choice to re-invent a testing framework that is not just another port and extension of JUnit. It features design changes to bring it more in line with where the .NET Framework is, and is heading. Examples of this are the use of Generics and Anonymous Delegates in Asserts.

They have also removed a great number of what they consider extraneous attributes see the quote from James post below:

    • [TestFixture] was removed entirely, so tests can be anywhere.
    • [Ignore] is expressed using the Skip= parameter on [Test].
    • [SetUp] and [TearDown] are removed.
    • [ExpectedException] was replaced with Assert.Throws.
    • [TestFixtureSetup] and [TestFixtureTearDown] are instead expressed as implementations of an interface (ITestFixture).
    • Support for IDisposable was added for tests.

This kind of thinking and approach is long overdue in my own opinion. It will be interesting to watch as the project matures. I have begun playing with it myself and so far I find it a lot more intuitive than any of the JUnit derivatives I have used in the past.

While I like mbUnit I have always had to think harder than I feel I should in order to use it. I get results that are often exactly opposite what I was expecting, which means that I am obviously not understanding something. It is also difficult to get help with mbUnit, while it is not abandonware it does not have a very active community, posts to their list server often go unanswered for long periods of time. And the Google Group discussion forums are none to active either.

Time will tell if xUnit suffers from the same lack of community or not, but so far it looks promising! 

Cheers,

Robert Porter


 
Categories: .NET | Agile | Programming | Reviews | TDD


At the office I was recently exposed to a tool called SQL Delta. Tools like this have been around for quite awhile, but this has to be the slickest and easiest to use interface I have seen.

The description of the tool from the products web page is:

"SQL Delta is a database compare and synchronization tool that performs both structure and data comparisons of SQL Server 2005, 2000 and 7 databases."

We use it here to sync up data and structure between the various build/test/uat/dev instances of our database back ends. It generates scripts, can run inside transactions, all the things you would expect. A little expensive for the home user but very affordable for a team.

Cheers,

Robert Porter


 
Categories: Programming | Reviews | SQL | Tools and Toys


Scott Hanselman posted an article (see below) about what he calls the "Nuclear Option" for restoring network connectivity issues. I took the commands from his post and created a cmd file that I could run and it works well.

I knew about some of these, but not all, and I can never remember the ones I did know when I need them. So this post is as much a reminder to me as anything else.

Go see his post for more information.

 

The Nuclear Option: Resetting The Crap Out Of Your Network Adapters in Vista
I was having a number of strange network issues on a laptop today. Here's the complete nuclear option for resetting your whole IP stack. This is for when "Diagnose and Repair" isn't cutting it. Thanks to JohnP for his help. Go to the Start Menu, type cmd and right click, and select "Run As Administrator" Type the following commands, each followed by pressing enter. ipconfig /flushdns nbtstat -R nbtstat -RR netsh int reset all netsh int ip reset netsh winsock reset ... (Read more at source)

 

Cheers,

Robert Porter


 
Categories: Hardware | Misc


September 21, 2007
@ 12:21 PM

A number of blogs incorporate scrolling blocks of text in their blog posts. This helps keep things organized and neat in the post.

The last time I needed to do this I used JavaScript, but since a lot of users turn scripting off for security reasons, I looked around and found a way to do it with good old CSS.

<div style="overflow:auto; height: 200px; width: 300px;>
<p>Some text to scroll around with.</p>
</div>

See it in action below:

 

Public Function GetClosedCount() As Long

 
        Dim oInboxAgenda As WFXTENDERLib.WfxAgenda
 
        Try
            ' Navigate to the Inbox for the Initial Routing Workflow user
            oInboxAgenda = oWFXConnection.Agenda(WORKBOX_TYPE_CLOSED)
            'Clear previous filters
            oInboxAgenda.SetFilter("", "", "")
            oInboxAgenda.SetFilter("Business Process", "=", "Initial Routing Workflow")
            'Refresh data so filter is applied
            oInboxAgenda.Refresh()
 
            Return oInboxAgenda.Count
        Catch eX As System.Exception
            MsgBox(eX.ToString)
        Finally
            System.Runtime.InteropServices.Marshal.ReleaseComObject(oInboxAgenda)
            oInboxAgenda = Nothing
        End Try
 
    End Function

 

So in a nutshell, a simple DIV and some CSS goes a long way. An added benefit is that this simple tag is supported on almost every browser.

I am still trying to figure out other ways to do this, I would prefer not having to hack the html view of my posts each time. But this works for now.

Cheers,

Robert Porter


 
Categories: ASP.NET | Browser | CSS | dasBlog


NerdTests.com says I'm a Kinda Dorky Nerd God.  What are you?  Click here!

Fun to do, give it a whirl and see what kind of Nerd you are! (Or are not.)


 
Categories: Misc


Microsoft has released the latest version of their Power Pack for Visual Basic 2005. Get your copy while it's still spinning!

Microsoft Visual Basic 2005 Power Packs 2.0 - Download

 

Microsoft Visual Basic 2005 Power Packs 2.0 - Information

 

Powerpack2

 

Cheers,

Robert Porter


 
Categories: .NET | Tools and Toys | VB.NET


September 20, 2007
@ 06:15 PM

This looks to be an interesting offering from the folks at Microsoft Live Services. SharedView is a collaboration system for small groups. Currently appears to be limited to 15 concurrent users, which should be enough for most uses.

Take a look here, and see what you think!

 

Cheers,

Robert Porter


 
Categories: Reviews | Tools and Toys


September 20, 2007
@ 04:41 PM

I have recently been experimenting (Again) with adding Unit Testing to several of the side projects I work on. And I have finally settled on the following tool combination.

I stayed away from NUnit because mbUnit appears to be so much more extensible. And the integration with TestDriven.Net is excellent.

XtUnit has recently come to my attention as well. Check this blog entry on Roy Osherove's blog for more info. This is the approach I hope to take in solving the rather messy issue of cleaning my database out after every test run.

_____________________________________________________________________________________________________

Update: When I got home I reread Roy's post and here is a link to another of his posts that has even more useful info. ______________________________________________________________________________________________________

I have been using CCNet for some time now to do my continuous integration builds, and thought it was time to begin adding tests and code coverage as well as FxCop analysis as several of the projects are within sight of a release window now.

More on that later...

 

Robert Porter


 
Categories: Programming | Tools and Toys