.NetSpec

**** Moved ****

This project has been moved to gitorious: http://gitorious.org/netspec

Introduction

.NetSpec is a small test extension framework for the Visual Studio Testing Framework. Its main goals are:

Behaviour driven development (BDD)
BDD is a software development technique which in many ways is similar to Test Driven Development (TDD). Many people consider it an enhancement of TDD. The main goal in BDD is that tests should describe the behaviour of your classes, and thus provide documentation of your code using code. It also makes it easier to write tests, because the focus has switched from "what to test" to "how should this class behave in differnt scenarios". You can read more about BDD on Wikipedia or http://behaviour-driven.org/

News

2009-03-18: Fixed bug reported where "expected" and "actual" were reversed
2008-09-12: Adding ShouldBeOfType<T>() and Enumerable.ShouldBeEmpty()
2008-04-11: Trx-converter added to .NetSpecExporter
2007-11-12: Added an AgileDox-like exporter for Visual Studio tests. Does not require .NetSpec.
2007-11-12: Added special hadling for strings (ShouldContain, ShouldNotContain, ShouldMatch and ShouldNotMatch) and enumerables/lists (ShouldContain/ShouldNotContain)
2007-11-07: Added ShouldBeSameAs/ShouldNotBeSameAs + Strong naming
2007-10-31: First version

Version 3.5 - (for .NET Framework 3.5 only - requires Visual Studio 2008)

The new extension methods in .NET 3.5 allows for a really nice syntax:

[TestClass]
    public class StackDescription
    {
        Stack<String> stack = new Stack<String>();

        [TestMethod]
        public void ShouldReturnTopElementOnPop()
        {
            stack.Push("car");
            stack.Push("Elephant");
            stack.Pop().ShouldBe("Elephant");
        }
        [TestMethod]
        public void ShouldUpdateCountOnPush()
        {
            stack.Count.ShouldBe(0);
            stack.Push("s");
            stack.Count.ShouldBe(1);
            stack.Push("x");
            stack.Count.ShouldBe(2);
        }

As you can see you can now write the asserts using a method called ShouldBe(). Personally I think this makes the test a lot easier to read.

The syntax for expecting exceptions has also changed:

[TestMethod]
        public void ShouldThrowExceptionOnPoppingEmptyStack()
        {
            stack.Count.ShouldBe(0);
            Call.To(delegate { stack.Pop(); }).ShouldThrow<InvalidOperationException>();
        }

You write whatever code you expect to throw an exception inside a delegate block, and the ShouldThrow method checks that the exception was actually caught and was of correct type.

Note that the TestClass and TestMethod attributes are kept to allow the tests to be run using the Visual Studio test view and the TFS builds.

See Using version 3.5 for more information

Version 2.0 - (for .NET Framework versions >= 2.0 - discontinued)

Because .NET 2.0 does not support the extension methods, the syntax is a little different there:

[TestClass]
    public class StackDescription
    {
        Stack<string> stack = new Stack<String>();

        [TestMethod]
        public void ShouldReturnPushedElementOnPop()
        {
            stack.Push("car");
            stack.Push("Elephant");
            Result.Of(stack.Pop()).ShouldBe("Elephant");
        }
        [TestMethod]
        public void ShouldUpdateCountOnPush()
        {
            Result.Of(stack.Count).ShouldBe(0);
            stack.Push("s");
            Result.Of(stack.Count).ShouldBe(1);
            stack.Push("x");
            Result.Of(stack.Count).ShouldBe(2);
        }

You have to use the Result.Of() together with ShouldBe() here.

The syntax for expecting exceptions, is the same as above.

See Using version 2.0 for more information

Tools

Name Description
.NetSpecExporter AgileDox-like exporter for Visual Studio tests. Does not require .NetSpec.

What about NSpec and NSpecify?

NSpec and NSpecify are built around custom attributes and a custom testrunner. One of the goals for .NetSpec is to integrate fully with the Visual Studio test views and the TFS builds without requiring any changes.

License

You can freely use the DLLs as a tool when developing software, though you may not include the DLLs as a part of a product without consent from the .NetSpec developers. All derivative work of the .NetSpec source code, must also be open source (GPL).

Source code repository

https://boss.bekk.no/repos/projects/NetSpec

Download

Download Required Visual Studio/.NET version
NetSpec-3.5.dll Visual Studio 2008 / .NET 3.5
NetSpec-2.0.dll >= Visual Studio 2005 / .NET 2.0

Developers

Got any good ideas and/or want to join? Please contact Erlend Oftedal

Contributors

Comments

Anonymous says:

I really like your library that you are providing - thank you.

 I don't know where else to place a bug, but you currently have the Actual and Expected backwards with the ShouldBe method. I did not check the other ones yet.

 ex. 10.ShouldBe(5); will give the error Expected<10> Actual<5> but it should read Expected<5> Actual<10>

Erlend Oftedal says:

Ah, you are correct. Sorry for not spotting your comment earlier. Fixed now.

Anonymous says:

It's not so simply to do a pretty good essay paper, first of all if you are intent. I consult you to find <a href=" http://www.qualityessay.com">buy an essay</a> and to be devoid from scruple that your work will be done by essay writers


Browse Space

- Pages
- News
- Labels
- Attachments
- Bookmarks
- Mail
- Activity
- Advanced

Explore Confluence

- Popular Labels
- Notation Guide

Your Account

Log In

 

Other Features

Add Content

- Add Comment