MSTest integration

Mar 9, 2009 at 9:57 PM
Where can I find a tutorial that shows how to use NBehave with MSTest? I see the version 0.4 has a lib called "NBehave.Spec.MSTest.dll". I am assuming it is possible to use NBehave with VSTS/MSTest.


Thank you!
Coordinator
Mar 10, 2009 at 9:22 PM
Well, I think its the easiest is to check the code that test that functionality because we havent created any tutorials.
Here's a piece of code from SpecBaseSpecs.cs in project NBehave.Spec.MSTest.Specs

using Microsoft.VisualStudio.TestTools.UnitTesting;
using Rhino.Mocks;
using Rhino.Mocks.Exceptions;
using Context = Microsoft.VisualStudio.TestTools.UnitTesting.TestClassAttribute;
using Specification = Microsoft.VisualStudio.TestTools.UnitTesting.TestMethodAttribute;
using NBehave.Spec.MSTest;

[Context]
    public class When_initializing_the_SpecBase_with_mocks : SpecBase<StopWatch>
    {
        private ITimer _timer;

        protected override StopWatch Establish_context()
        {
            _timer = CreateDependency<ITimer>();

            _timer.Stub(x => x.Start(null)).IgnoreArguments().Return(true);

            return new StopWatch(_timer);
        }

        protected override void Because_of()
        {
            Sut.Start();
        }

        [Specification]
        public void should_call_the_before_each_spec_before_starting_the_specification()
        {
            _timer.AssertWasCalled(x => x.Start(null), opt => opt.IgnoreArguments());
        }
    }

    public class StopWatch
    {
        private readonly ITimer _timer;

        public StopWatch()
        {
        }

        public StopWatch(ITimer timer)
        {
            _timer = timer;
        }

        public void Start()
        {
            _timer.Start("");
        }
    }

    public interface ITimer
    {
        bool Start(string reason);
        void Start();
    }


[Context]
    public class When_initializing_the_SpecBase_with_mocks : SpecBase<StopWatch>
    {
        private ITimer _timer;

        protected override StopWatch Establish_context()
        {
            _timer = CreateDependency<ITimer>();

            _timer.Stub(x => x.Start(null)).IgnoreArguments().Return(true);

            return new StopWatch(_timer);
        }

        protected override void Because_of()
        {
            Sut.Start();
        }

        [Specification]
        public void should_call_the_before_each_spec_before_starting_the_specification()
        {
            _timer.AssertWasCalled(x => x.Start(null), opt => opt.IgnoreArguments());
        }
    }

    public class StopWatch
    {
        private readonly ITimer _timer;

        public StopWatch()
        {
        }

        public StopWatch(ITimer timer)
        {
            _timer = timer;
        }

        public void Start()
        {
            _timer.Start("");
        }
    }

    public interface ITimer
    {
        bool Start(string reason);
        void Start();
    }