Friday, February 8, 2013

NBehave

I'm playing with NBehave today.  First of all, I'm using Visual Studio 2012 and I'm planning to use MSTest.  I went through various instructions for installing and I finally stumbled onto this article that worked:

Github NBehave Assert Extensions

I went to the Tools -> Library Package Manager -> Package Manager Console.  Then I copied and pasted this command:

Install-Package nbehave.spec.mstest

and hit enter.  It did some processing and voila!  It worked.  OK, actually, I had previously added a using and some sample code:

using NBehave.Spec.MSTest;

namespace OSIM.UnitTests
{
    [TestClass]
    public class Specification
    {
        [TestMethod]
        public void TestMethod1()
        {
            1.ShouldEqual(1);
            2.ShouldNotEqual(1);
            var numbers = new[] { 1, 2, 3 };
            numbers.ShouldContain(2);
        }
    }
}

Then I ran the unit test and it passed.  I changed one of the expected values (the should equal I changed to a 3) and re-ran the tests to see if it failed.  It failed as expected.

Hopefully you stumbled onto this posting and cut right to the chase.  I had to go through a few failed install instructions before I stumbled onto this.  Sometimes things are difficult in getting started.  After you learn the tricks, then it's a piece of cake.