Rash thoughts about .NET, C#, F# and Dynamics NAV.


"Every solution will only lead to new problems."

Sunday, 8. November 2009


"Getting started" with NaturalSpec – (Updated 08.11.2009)

Filed under: .NET,F#,NaturalSpec — Steffen Forkmann at 10:48 Uhr

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.

Creating a spec project

Rename Module1.fs in ListSpec.fs and delete script.fsx from the project:

Solution explorer

Create a folder “Lib” and unzip the NaturalSpec libraries into it.

Add NaturalSpec.dll and nunit.framework.dll as references to your project:

Adding project references

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:

Run spec with TestDriven.net

If you don’t like the TestDriven.Net test runner you might want to use the NUnit GUI runner. The output should look like:

NUnit Gui runner

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.

Tags: , , , , ,

6 Comments »

  1. [...] More about NaturalSpec Steffen Forkmann’s “Getting Started” with NaturalSpec Steffen Forkmann’s Testing QuickSort with NaturalSpec Steffen Forkmann’s Using NaturalSpec to [...]

    Pingback by Rick Minerich's Development Wonderland : F# for Testing and Analysis at Code Camp 11 New England — Friday, 27. March 2009 um 23:37 Uhr

  2. [...] my last two articles I gave an introduction in NaturalSpec and showed how to get started. This time I will show how we can use NaturalSpec to write automatically testable scenarios for C# [...]

    Pingback by Using NaturalSpec to create a spec for C# projects » Rash thoughts about .NET, C#, F# and Dynamics NAV. — Sunday, 8. November 2009 um 11:03 Uhr

  3. [...] can download NaturalSpec at GoogleCode and follow the “Getting started” tutorial in order to write your first automatically testable [...]

    Pingback by Introducing NaturalSpec – A Domain-specific language (DSL) for testing – Part I » Rash thoughts about .NET, C#, F# and Dynamics NAV. — Sunday, 8. November 2009 um 11:11 Uhr

  4. [...] my last articles I gave an introduction in NaturalSpec, showed how to get started and demonstrated how we can use NaturalSpec to write automatically testable scenarios for C# [...]

    Pingback by Mocking objects with NaturalSpec » Rash thoughts about .NET, C#, F# and Dynamics NAV. — Sunday, 8. November 2009 um 15:24 Uhr

  5. [...] doing TDD, so we need some sort of testing framework.  I decided to go with NaturalSpec.  This means we’ll need to download the package from github, build it, and also download and [...]

    Pingback by Learning F# with TDD: Part 1 — Sunday, 21. August 2011 um 22:59 Uhr

  6. [...] Test(s)” for a project or solution, the tests would not be found as described in the getting started post, so I would see something like “0 passed, 0 failed, 0 skipped, [...]

    Pingback by Learning F# with TDD: Part 2 | The Endless Obsession — Thursday, 12. January 2012 um 4:51 Uhr

RSS feed for comments on this post. | TrackBack URI

Leave a comment

XHTML ( You can use these tags): <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong> .