posted on Monday, September 27, 2004 1:27 PM
by
mlorengo
Refrigerators, Unit Testing & NAnt
Hi, I missed my entry on Friday as I've been a bit busy fixing the
refrigerator. It was making a funny noise and the door sags a bit due to all the
bottles in the door. I also cleaned out a small litter of dust bunnies from the
condenser coils, woo boy can they multiply. Anyway, I'll give a shout out to the
RepairClinic.com for
helping me troubleshoot the problems.
Unit Testing with NUnit
You may recall that my last entry had to do with comparing NUnit & MbUnit.
Well MbUnit has a problem with users running as Non-Admin's, it basically fails
when it is creating the .html report of the results.
I submitted this to
mbunit.tigris.org. And received this
response from Jonathan deHalleux after
some discussion.
------- Additional comments from
Jonathan de Halleux Sun Sep 26
03:41:36 -0700 2004 -------
I've been talking about this to Jamie Cansdale. He said that Admin installs
were not supported right now but they are a priority and should be by the 30.
So until this issue is resolved, I'll be using NUnit for my unit testing. The
nice thing about Jonathan's NUnit Add-In for Visual Studio is that it works with
either NUnit or MbUnit. I've begun writing my test's and so far have come up
with the following
- An Initial Cellar must contain 0 Items
- After adding an Wine object, the Cellar must contain only 1 Item
- If I try and add a null item, I should receive an ArgumentNullException
- I should be able to add duplicate wine objects (I'll need to determine
if I should really add another wine object, or just add a count property to
the wine class, I'm thinking I add duplicates, opinions?)
- I should be able to remove a wine from the cellar and see the count
decrement by one
- I should not be able to remove a non-existent wine from the cellar.
(Should this cause an exception? Or should I do something else?)
- I should be able to iterate through all the wines in the cellar
- I should be able to retrieve a wine from the cellar.
- I should be able to update the properties of a wine in the cellar
- Any other suggestions?
I've coded tests for the first 3 cases and have currently 2 classes (Cellar &
Wine). They currently pass all the tests, and I've checked them into Subversion
(Source Code Control). Before I get too far along, I want to begin automating my
builds, it's better to start early rather than try and retrofit everything.
Using NAnt
As I said in a previous post, I'll be using NAnt for my builds. I have VS2005
installed so I could be using MS Build, perhaps later. For NAnt I'll have 3
build files
- D:\VirtualCellar\default.build
-
D:\VirtualCellar\Lorengo.VirtualCellar.Business\default.build
-
D:\VirtualCellar\Lorengo.VirtualCellar.Business.Tests\default.build
Here is the overall build file. You'll notice that I call the other build
files from this file.
<?xml version="1.0"?>
<project name="VirtualCellar" default="build" basedir=".">
<property name="debug" value="true"/>
<property name="build.deploy" value="release"/>
<property name="build.tests.results" value="Results.zip"/>
<property name="build.business" value="Lorengo.VirtualCellar.Business"/>
<property name="build.business.tests" value="Lorengo.VirtualCellar.Business.Tests"/>
<target name="clean" description="cleans build directory">
<delete dir="${build.deploy}" verbose="true" failonerror="false"/>
<mkdir dir="${build.deploy}"/>
<nant buildfile="${build.business}/default.build" target="clean"/>
<nant buildfile="${build.business.tests}/default.build" target="clean"/>
</target>
<target name="build" description="compiles projects" depends="clean">
<nant buildfile="${build.business}/default.build"/>
<nant buildfile="${build.business.tests}/default.build"/>
<copy todir="${build.deploy}/bin" file="${build.business}/bin/debug/${build.business}.dll"/>
</target>
</project>
|
Here's the build file for the business layer. One of the nice things about
NAnt 0.84 is the
<solultion> task that allow you to specify the Visual Studio Project file.
Before you had to run the command line compiler on each .cs file.
<?xml version="1.0"?>
<project name="Lorengo.VirtualCellar.Business" default="build" basedir=".">
<property name="nant.settings.currentframework" value="net-1.1"/>
<property name="basename" value="Lorengo.VirtualCellar.Business"/>
<property name="debug" value="true"/>
<property name="build.dir" value="bin"/>
<target name="clean" description="cleans build directory">
<delete dir="${build.dir}" verbose="true" failonerror="false"/>
</target>
<target name="build" depends="clean">
<tstamp>
<formatter property="DSTAMP" pattern="yyyy-MM-dd"/>
<formatter property="TSTAMP" pattern="HH:mm"/>
</tstamp>
<echo message="Build started at : ${DSTAMP} - ${TSTAMP}"/>
<solution configuration="debug">
<projects>
<includes name="${basename}.csproj"/>
</projects>
</solution>
</target>
</project> |
The build file for the Lorengo.VirtualCellar.Business.Tests assembly is
very similar to the above build file. To compile my files I simply type
D:\VirtualCellar>nant
NAnt 0.84 (Build 0.84.1455.0; net-1.0.win32; release; 12/26/2003)
Copyright (C) 2001-2003 Gerry Shaw
http://nant.sourceforge.net
Buildfile: file:///D:/VirtualCellar/default.build
Target(s) specified: build
[sysinfo] Setting system information properties under sys.*
clean:
[delete] Deleting directory D:\VirtualCellar\release.
[delete] Deleting file D:\VirtualCellar\release\bin\Lorengo.VirtualCellar.Business.dll.
[delete] Deleting directory D:\VirtualCellar\release\bin.
[delete] Deleting directory D:\VirtualCellar\release.
[mkdir] Creating directory D:\VirtualCellar\release.
[nant] D:\VirtualCellar\Lorengo.VirtualCellar.Business\default.build clean
Buildfile: file:///D:/VirtualCellar/Lorengo.VirtualCellar.Business/default.build
Target(s) specified: clean
clean:
[delete] Deleting directory D:\VirtualCellar\Lorengo.VirtualCellar.Business\bin.
[delete] Deleting file D:\VirtualCellar\Lorengo.VirtualCellar.Business\bin\Debug\Lorengo.VirtualCellar.Bus
[delete] Deleting file D:\VirtualCellar\Lorengo.VirtualCellar.Business\bin\Debug\Lorengo.VirtualCellar.Bus
[delete] Deleting directory D:\VirtualCellar\Lorengo.VirtualCellar.Business\bin\Debug.
[delete] Deleting directory D:\VirtualCellar\Lorengo.VirtualCellar.Business\bin.
BUILD SUCCEEDED
Total time: 0.1 seconds.
[nant] D:\VirtualCellar\Lorengo.VirtualCellar.Business.Tests\default.build clean
Buildfile: file:///D:/VirtualCellar/Lorengo.VirtualCellar.Business.Tests/default.build
Target(s) specified: clean
clean:
[delete] Deleting directory D:\VirtualCellar\Lorengo.VirtualCellar.Business.Tests\bin.
...(stuff deleted)
[delete] Deleting directory D:\VirtualCellar\Lorengo.VirtualCellar.Business.Tests\bin.
BUILD SUCCEEDED
Total time: 0.1 seconds.
build:
[nant] D:\VirtualCellar\Lorengo.VirtualCellar.Business\default.build
Buildfile: file:///D:/VirtualCellar/Lorengo.VirtualCellar.Business/default.build
Target(s) specified: build
clean:
[delete] D:\VirtualCellar\Lorengo.VirtualCellar.Business\default.build(9,4):
Cannot delete directory D:\VirtualCellar\Lorengo.VirtualCellar.Business\bin. The directory does not exist.:
NAnt.Core.BuildException: D:\VirtualCellar\Lorengo.VirtualCellar.Business\default.build(9,4):
Cannot delete directory D:\VirtualCellar\Lorengo.VirtualCellar.Business\bin. The directory does not exist.
at NAnt.Core.Tasks.DeleteTask.ExecuteTask()
at NAnt.Core.Task.Execute()
build:
[tstamp] Monday, September 27, 2004 4:19:00 PM.
[echo] Build started at : 2004-09-27 - 16:19
[solution] Starting solution build.
[solution] Building Lorengo.VirtualCellar.Business [debug]...
BUILD SUCCEEDED
Total time: 0.9 seconds.
[nant] D:\VirtualCellar\Lorengo.VirtualCellar.Business.Tests\default.build
Buildfile: file:///D:/VirtualCellar/Lorengo.VirtualCellar.Business.Tests/default.build
Target(s) specified: build
clean:
[delete] D:\VirtualCellar\Lorengo.VirtualCellar.Business.Tests\default.build(9,4):
Cannot delete directory D:\VirtualCellar\Lorengo.VirtualCellar.Business.Tests\bin. The directory does not exist.:
NAnt.Core.BuildException: D:\VirtualCellar\Lorengo.VirtualCellar.Business.Tests\default.build(9,4):
Cannot delete directory D:\VirtualCellar\Lorengo.VirtualCellar.Business.Tests\bin. The directory does not exist.
at NAnt.Core.Tasks.DeleteTask.ExecuteTask()
at NAnt.Core.Task.Execute()
build:
[tstamp] Monday, September 27, 2004 4:19:01 PM.
[echo] Build started at : 2004-09-27 - 16:19
[solution] Starting solution build.
[solution] Building Lorengo.VirtualCellar.Business [debug]...
[solution] Building Lorengo.VirtualCellar.Business.Tests [debug]...
[copy] Copying 25 files to D:\VirtualCellar\Lorengo.VirtualCellar.Business.Tests\bin\Debug\.
[copy] Copying 2 files to D:\VirtualCellar\Lorengo.VirtualCellar.Business.Tests\bin\Debug\.
[copy] Copying 12 files to D:\VirtualCellar\Lorengo.VirtualCellar.Business.Tests\bin\Debug\.
BUILD SUCCEEDED
Total time: 1.3 seconds.
[copy] Copying 1 file to D:\VirtualCellar\release\bin.
BUILD SUCCEEDED
Total time: 2.9 seconds. |
This allows me to build my complete solution from the command line. There
are a few more things that I will want to do before I get back to coding
some of my unit tests. They all relate to implementing a
Continuous Integration environment.