Skip to content
Leo Arnold edited this page May 22, 2017 · 5 revisions

Start your editor and create a new C# project.

After that you should install the nbehave nuget package.

Install-Package nbehave

Do you want to run this from the console and/or in your build script? If yes, then

Install-Package nbehave.runners

Do you have Resharper? Then install the R# plugin matching your version of R#

  • 6.0 Install-Package nbehave.resharper60
  • 6.1.1 Install-Package nbehave.resharper611
  • 7.01 Install-Package nbehave.resharper701
  • 7.1 Install-Package nbehave.resharper71

Don't have Resharper? or maybe you'd like some syntax highlighting for the .feature files? Then install the Visual Studio plugin, it's available at the Visual Studio Gallery. You can get to the Visual Studio Gallery from within Visual Studio (Menu Tools, then Extension Manager...)

If Resharper and the Visual Studio plugin isn't an option for you, well then you could use NBehave-Console.exe or the EmbeddedRunner.

Now, add a text file to your project, name it HelloWorld.feature

Feature: HelloWorld
  A narrative is optional

Scenario: Login
  Given I am not logged in
  When I log in as Morgan with a password SecretPassw0rd
  Then I should see a message, "Welcome, Morgan!"

Try running it, the steps should be pending. If you use the R# runner you will get suggesions on how to implement the steps.

Now, add the following code.

using NBehave.Narrator.Framework;
using NBehave.Spec.NUnit;

[ActionSteps]
public class HelloWorldSteps
{
    [Given("I am not logged in")]
    public void LogOut()
    {
        // put code here.
    }

    [When("I log in as $username with a password $password")]
    public void LogIn(string username, string password)
    {
        // put code here.
    }

    [Then("I should see a message, \"$message\"")]
    public void CheckMessage(string message)
    {
        // put code here.
    }
}

Now run the feature again, you should have 3 passing steps, a passing scenario and a passing feature.

Thats it!

Clone this wiki locally