In my last article (Introducing NaturalSpec – A Domain-specific language (DSL) for testing) I used NaturalSpec in two small samples. This time I will show how we can set up a NaturalSpec environment to write our first automatically testable scenarios.
1. Choosing an IDE
The first step is to choose an integrated development environment for NaturalSpec. At the current project status you should be able to use NaturalSpec with Visual Studio 2008, Visual Studio 2010 beta 2, the freely available Visual Studio 2008 Shell or the free IDE SharpDevelop 3.0.
2. Installing the testing framework
As NaturalSpec uses NUnit as the underlying testing framework we have to install NUnit 2.5. I also recommend installing TestDriven.Net in order to get a Unit Test runner within Visual Studio.
3. Installing F#
NaturalSpec is completely written in F# and all specs will also be written in F#. This doesn’t imply you have to learn programming in F# but we need the F# compiler to get things working. You can download the F# October 2009 CTP from the Microsoft F# Developer Center.
4. Downloading the latest version of NaturalSpec
You can download a .zip with the latest NaturalSpec libraries from GoogleCode.
5. Creating a spec
This part is written for using Visual Studio 2008. If you use SharpDevelop or Visual Studio 2008 Shell this might differ in some detail.
Start Visual Studio 2008 and create a new F# class library.
Rename Module1.fs in ListSpec.fs and delete script.fsx from the project:
Create a folder “Lib” and unzip the NaturalSpec libraries into it.
Add NaturalSpec.dll and nunit.framework.dll as references to your project:
Copy the following code into ListSpec.fs:
module ListSpec
open NaturalSpec [<Scenario>] let When_removing_an_3_from_a_small_list_it_should_not_contain_3() = Given [1;2;3;4;5] |> When removing 3 |> It shouldn't contain 3 |> Verify
If you have TestDriven.Net installed you can run your spec via right click in the solution explorer:
If you don’t like the TestDriven.Net test runner you might want to use the NUnit GUI runner. The output should look like:
In addition the test runner should produce a Spec output file with the name “Spec.txt” within the same folder.
Summary
In a minimal environment you need SharpDevelop, the F# compiler, NUnit and the NaturalSpec libraries for using NaturalSpec.
In the next post I will show how you can use NaturalSpec to create a spec for C# projects.
Original article: "Getting started" with NaturalSpec – (Updated 08.11.2009)
©2013 Rash thoughts about .NET, C#, F# and Dynamics NAV.. All Rights Reserved.