Re.Mark

My Life As A Blog

Archive for April 2006

Limits to Independence

leave a comment »

The solution I described yesterday has a drawback – it increases the scope of the created class. This may be acceptable – it may even be desirable – in some instances, but there are situations where you have to think of something else. In the case of nspectre, a reference ValidatorFactory needs to held for the lifetime of an application because it compiles the specifications once when they are first required. So, if we were to hold references at class level in ValidatorFactory, they would never be eligible for garbage collection.
Let's say we have a class called, uninspiringly, Foo that creates an instance of class called – you guessed correctly – Bar. One solution is to create a protected method in Foo that returns a new instance of Bar. In our unit tests we subclass Foo and override the newly created protected method. Then we can either extract the interface from Bar and make Bar implement this interface (IBar) and mock Bar in the unit tests. It would also be possible to return a fake Bar – maybe by subclassing Bar.

Written by remark

April 26, 2006 at 8:05 pm

More Independence

leave a comment »

Having put in a few logging messages into nspectre to prove the principle, it's time to test the logging messages. Given that the design relies on an ILogger interface, this is fairly easy with mocks. What I noticed fairly quickly was a class that created another class – which meant that testing logging would mean testing it in more than the target class.
The solution is to extract an interface from the class being created by the target class and pass it to the target class in the constructor. Now I can also mock the class that was being created. In this instance, the code that results is more elegant. All tests have been updated and they all pass. Once more the tests have proven their worth – this kind of refactoring would have been scary without them.

Written by remark

April 25, 2006 at 10:57 pm

Look Sharp

leave a comment »

The beta version 2.0 of Resharper is available. I've used and been impressed by Resharper. Just over a year ago, I was coming back to VS.NET, having been using Eclipse for a while. I was amazed how far behind the game Visual Studio was in support for refactoring. Version 2.0 of Resharper includes a built-in tool for running unit tests à la Test Driven .NET. Intriguing.

Written by remark

April 23, 2006 at 10:16 pm

Posted in Tools

Who owns the code?

leave a comment »

I found this an interesting read. The article suggests the role of a Code Steward whose job:

is not to safeguard against concurrent-access, but to instead safeguard the integrity+consistency of that code (both conceptually and structurally) and to widely disseminate knowledge and expertise about it to others.

The measure of success, of course, is that the Code Steward's role becomes unnecessary – enabling them to reprise the role on other projects.

Written by remark

April 20, 2006 at 8:05 pm

Posted in General

Performancing

leave a comment »

The new version of Performancing for Firefox is out (version 1.2) – this version includes access to your Performancing metrics.

Written by remark

April 19, 2006 at 10:13 pm

Posted in Tools

Sunday Post

leave a comment »

Most of the logging support for nspectre is done (in CVS but not released.)  I need to extend the support to the ConfigurationReaders to complete the job.  Of course logging support does not equal logging.  I’ve put some logging in to a couple of classes and a couple of templates to prove the principle, now I need to expand that across the codebase (including testing the logging.)

Written by remark

April 16, 2006 at 2:06 pm

Posted in nspectre

Feed me

leave a comment »

I’d just got around to looking at Feedburner, when WordPress posted this.  Excellent.

Written by remark

April 16, 2006 at 1:56 pm

Posted in General