8. Appendices
8.1. Where can I find Spring?
The main Spring website is [http://www.springframework.org/]. This is the site for the Java version. The .NET version, currently under development (April 2005), can be found at [http://www.springframework.net/].

The download site is on [SourceForge]:

Once you have downloaded the zip file above, unzip it:

In this document, we have only used the contents of the [bin] folder:

In a Visual Studio project using Spring, you must always do two things:
- place the files above in the project’s [bin] folder
- add a reference to the [Spring.Core.dll] assembly to the project
8.2. Where can you find NUnit?
The main NUnit website is [http://www.nunit.org/]. The version available in April 2005 is 2.2.0:

Download this version and install it. The installation creates a folder containing the graphical testing interface:
The interesting part is in the [bin] folder:


The arrow above points to the graphical testing utility. The installation also added new items to the Visual Studio assembly repository, which we will explore now.
Let’s create the following Visual Studio project:
The class being tested is in [Person.vb]:

Public Class Person
' private fields
Private _name As String
Private _age As Integer
' default constructor
Public Sub New()
End Sub
' properties associated with private fields
Public Property name() As String
Get
Return _name
End Get
Set(ByVal Value As String)
_name = Value
End Set
End Property
Public Property age() As Integer
Get
Return _age
End Get
Set(ByVal Value As Integer)
_age = Value
End Set
End Property
' identity string
Public Overrides Function tostring() As String
Return String.Format("[{0},{1}]", name, age)
End Function
' init method
Public Sub init()
Console.WriteLine("Initializing person {0}", Me.ToString)
End Sub
' close method
Public Sub close()
Console.WriteLine("destroy person {0}", Me.ToString)
End Sub
End Class
The test class is in [NunitTestPersonne-1.vb]:
Imports System
Imports NUnit.Framework
<TestFixture()> _
Public Class NunitTestPerson
' object under test
Private person1 As Person
<SetUp()> _
Public Sub init()
' Create an instance of Person
person1 = New Person
' log
Console.WriteLine("setup test")
End Sub
<Test()> _
Public Sub demo()
' screen log
Console.WriteLine("start test")
' initialize person1
With person1
.name = "paul"
.age = 10
End With
' tests
Assert.AreEqual("paul", person1.name)
Assert.AreEqual(10, person1.age)
' screen log
Console.WriteLine("end of test")
End Sub
<TearDown()> _
Public Sub destroy()
' monitoring
Console.WriteLine("teardown test")
End Sub
End Class
Several things to note:
- methods are assigned attributes such as <Setup()>, <TearDown()>, ...
- for these attributes to be recognized, the following must be true:
- the project references the assembly [nunit.framework.dll]
- the test class imports the namespace [NUnit.Framework]
The reference is added by right-clicking on [References] in the Solution Explorer:
![]() | ![]() |

The assembly [nunit.framework.dll] should be in the list if the [NUnit] installation was successful. Simply double-click the assembly to add it to the project:

Once this is done, the test class [NunitTestPersonne] must import the [NUnit.Framework] namespace:
The attributes of the test class [NunitTestPersonne] should then be recognized.
- The <Test()> attribute designates a method to be tested
- The <Setup()> attribute designates the method to be executed before each method being tested
- The <TearDown()> attribute designates the method to be executed after each method being tested
- The Assert.AreEqual method allows you to test the equality of two entities. There are many other methods of the Assert.xx type.
- The NUnit utility stops the execution of a tested method as soon as an [Assert] method fails and displays an error message. Otherwise, it displays a success message.
Let’s configure our project to generate a DLL:

The generated DLL will be named [nunit-demos-1.dll] and will be placed by default in the project’s [bin] folder. Let’s build our project. We get the following in the [bin] folder:

Now let’s launch the Nunit graphical testing utility. Remember that it is located in <Nunit>\bin and is named [nunit-gui.exe]. <Nunit> refers to the [Nunit] installation folder. We get the following interface:

Let’s use the [File/Open] menu option to load the [nunit-demos-1.dll] DLL from our project:

[Nunit] can automatically detect the test classes contained in the loaded DLL. Here, it finds the [NunitTestPersonne] class. It then displays all the methods of the class that have the <Test()> attribute. The [Run] button allows you to run the tests on the selected object. If this is the [NunitTestPersonne] class, all displayed methods are tested. You can test a specific method by selecting it and clicking [Run]. Let’s run the class:

A successful test on a method is indicated by a green dot next to the method in the left window. A failed test is indicated by a red dot.
The [Console.Out] window on the right shows the screen output produced by the tested methods. Here, we wanted to follow the progress of a test:
- Line 1 shows that the <Setup()> attribute method is executed before the test
- Lines 2–3 are generated by the [demo] method being tested (see the code above)
- Line 4 shows that the <TearDown()> attribute method is executed after the test

