Tuesday, January 22, 2008

Excluding Certain NUnit Tests

Another developer in my group wrote a group of Automation Tests that verify the conversion of some data within our database. He added these tests to our existing Testing assembly (. We are also using NAnt to run and validate the tests in our Testing assembly as part of our build process. However, we did not want this test to be included as part of the normal tests run during the build process. So to accommodate this we added a category of DatabaseConversion to the test fixture:



Then I modified the exclude list for the NAnt task as follows:

<exec program="nunit-console.exe" basedir="${nunit.dir}" workingdir="${working.dir}">
  <arg value="${testassembly}" />
  <arg value="/xml:UnitTests.xml" />
  <arg value="/exclude:DatabaseConversion" />

As I thought about this, I was worried about the fact that if someone forgets to put the appropriate category on a test or we decide that another category of tests needs to be excluded we would need to update the NAnt task again. So I went and did some digging in the NUnit documentation and found that there is an Explicit attribute that you can add at the TestFixture or Test level. The ExplictAttribute documentation describes this as follows:

"The Explicit attribute causes a test or test fixture to be ignored unless it is explicitly selected for running. The test or fixture will be run if it is selected in the gui, if its name is specified on the console runner command line as the fixture to run or if it is included by use of a Category filter.

An optional string argument may be used to give the reason for marking the test Explicit.

If a test or fixture with the Explicit attribute is encountered in the course of running tests, it is skipped unless it has been specifically selected by one of the above means. The test does not affect the outcome of the run at all: it is not considered as ignored and is not even counted in the total number of tests. In the gui, the tree node for the test remains gray and the status bar color is not affected."

So now the code looks like the following:

[TestFixture, Explicit]


This is perfect for what we are trying to accomplish as it basically will exclude the test unless it is explicitly selected to be run. And I do not need to be worried about the exclude list for the NAnt task having .

Composition over Inheritance

Recently when walking through the design of some new features for an application, another developer asked: "Why should I use composition over inheritance?" I attempted to answer that question, and felt that I did not do as good of a job answering it as I would have liked. I was recently looking for something else on Phil Haack's blog and ran across this good article, Composition over Inheritance and other Pithy Catch Phrases.

I think that Phil does a very nice job of explaining the argument and the key point in why this question should be asked: "The goal is not to bend developers to the will of some specific patterns, but to get them to think about their work and what they are doing."  Please give this article a read for more details.

Wednesday, January 16, 2008

Getting Assembly Public Key

I recently needed to get the public key of an assembly, so I went straight to the GAC (Global Assembly Cache) located at %WinDir%\assembly, knowing that the public key token is a column in that view via the file explorer. However, the assembly that I wanted was not registered in the GAC. So I navigated to the location of the assembly on my hard drive and started poking around in the properties thinking the public key value might be in there, no luck. Then I remembered Lutz Roeder's Reflector. I opened the assembly using Reflector and there it was down in the details for that assembly. Another reason to have this very handy utility around.



Thursday, January 3, 2008

A state aware generic list


A state aware generic list is a great post, showing you how to keep track of the state of the objects contained in a generic list. Mads uses a very simple technique for tracking the state of his list. Looks like something that can be very useful if you are rolling your own objects and you want to track the state of generic lists.