Posts Tagged ‘specifications’
A few months ago I started with BDD (Behaviour Driven Development). The first thing I noticed with most frameworks (MSpec, NBehave) is that you either need a new test runner tool (Galio) or need quite a bit of tweaking to implement the respective framework with Test-Driven.NET or Resharper’s test runner (Galio has a Resharper plugin).
This isn’t a problem in most cases, but what if you need to run these tests on Team-City or Cruise-Control? Now the complexity of the tweaking starts to become quite a different ball game!
Luckily there is an open-source tool called StoryQ which runs on NUnit and doesnt require any tweaking. The developer can run this with his usual test-runner tool and best of all, nothing has to change on the Buildserver.
Besides requiring no tweaking, StoryQ is a pretty competitive BDD tool altogether and provides loads of nifty features.
The idea is that “Tests” should be viewed as “Specs”, because this removes much of the confusion of TDD especially for beginners.
Your typical Unit test (or Spec) would look like this:
using NUnit.Framework;
using StoryQ.Framework;
namespace StoryQ.Tests.Documentation
{
[TestFixture]
public class SimpleDocumentationSpec
{
[Test]
public void WritingSpecificationsToBegin()
{
Story story = new Story("writing executable specifications");
story.AsA("business person")
.IWant("to write executable specifications")
.SoThat("a developer can implement them")
.WithScenario("Writing specifications")
.Given("That i have written everything in text")
.When("the test is run")
.Then("the test result should be pending")
.WithScenario("Writing specifications again")
.Given("That i have written everything in text")
.And("still have no asserts")
.And("and have another condition")
.When("the test is run")
.And("I am happy")
.Then("the test result should be pending")
.And("here's just some more and's");
story.Assert();
}
}
}
This would present an NUnit output result of:
SimpleDocumentationSpec.WritingSpecificationsToBegin : IgnoredPending
Story: writing executable specifications
As a business person
I want to write executable specifications
So that a developer can implement them
Scenario 1: Writing specifications
Given That i have written everything in text *Pending
When the test is run *Pending
Then the test result should be pending *Pending
Scenario 2: Writing specifications again
Given That i have written everything in text *Pending
And still have no asserts *Pending
And and have another condition *Pending
When the test is run *Pending
And I am happy *Pending
Then the test result should be pending *Pending
And here's just some more and's *Pending
You can then start adding functionality with the given scenarios like so:
using NUnit.Framework;
using StoryQ.Framework;
namespace StoryQ.Tests.Documentation
{
[TestFixture]
public class UsingNarrativesSpec
{
[Test]
public void WritingExecutablePassingSpecificationsWithNarratives()
{
Story story = new Story("writing executable specifications");
story.AsA("business person")
.IWant("to write executable specifications")
.SoThat("a developer can implement them")
.WithScenario("Writing specifications again")
.Given(Narrative.Text("I have a narrative"))
.When(() => TheTestIs_("run"))
.Then(Narrative.Exec("this will now pass", passMe));
story.Assert();
}
static void passMe()
{
Assert.IsTrue(true);
}
static void TheTestIs_(string s)
{
Assert.AreEqual(s, "run");
}
}
}
Which will give you the output of:
UsingActionsSpec.WritingExecutableSpecificationsAsActions : PassedStory: writing executable specifications
As a business person
I want to write executable specifications
So that a developer can implement them
Scenario 1: Writing specifications
Given That i have written everything in text *Pending
When the test is run *Pending
Then the test result should be pending *Pending
Scenario 2: Writing specifications again
Given That everything isnt Passed
When The test is run Passed
Then the test result should be pending *Pending
There are many more options and different ways to implement the scenarios on the StoryQ home page.
Another great feature about StoryQ is to convert your english written stories into C# tests. Yes, you read that right! It will even write the code for you! By using convention that can be tought to your “Product Owners”, you can literally copy and paste their requirements to a tool which will present the generated c# test.