Home
Releases
Discussions
Issue Tracker
Source Code
Stats
People
License
RSS RSS Feed
Search Wiki:
Project Description
StoryQ is a C# 3.5 framework for Behaviour-Driven Development (BDD). Similar to nBehave, but overall simplier. It is made to work within NUnit and MSUnit test runner lifecycles to make integration easier. Stories can be created either in plain text and then passively generated as C# (using to WPF application) or are directly entered in tests. Output is either to console or to html files. We include these html files on the build server for visibility beyond the developers. Each story's output is either pending, passed or failed - just as you would expect from NUnit.

Sorry, I only have code samples available at the moment. All of these samples are included in the project to explain the code. This work comes out of a project. We developed StoryQ in three days to try and simplify the approach used in other projects (ie nBehave/Specify#). Check them out they may be what you want - but I found them slow to start with; I'm hoping you should be up and going in 10mins. We also have restricted ourselves to using existing test runners (eg NUnit GUI, ReSharper and TestDriven.Net). As an aside, I also couldn't get rspec (:-() going in a .Net environment (ie via IronRuby or ruby's dotnet binding library) - so this is the end result. I hope you find it useful. Here's Rob's further description of this project.

StoryQ was written to reduce the time to start describing behaviour at the application level. It's based on a real project with features that include:

* plain text scenarios
* having more than one story or scenario in a file
* built on NUnit/MSUnit (rather than self-hosting)
* avoid creating new annotation/attributes
* auto-conversion of string arguments to numbers in the report
* pending steps generated for anything which hasn’t been defined yet (these don’t break the build)
* errors from scenarios are rethrown after the full scenario has been described - finishes with an Assert
* output reports to Console or HTML

There some elements of BDD that it isn't currently doing.

* Should or Ensure assertions
* spec framework an object level - "Describe It Should" syntax (see rspec)
* "In Order To" syntax (see JBehave2)
* tagging scenarios - can use categories but doesn't affect reporting as yet
* running reports of stories passed against an original set of stories

Here are four examples using NUnit runner:

* Simple example for analysis
* Using a "Narrative" to execute the test
* Using an Action to execute the test
* Complex example with output to html

StoryQ also comes with a GUI helper to convert stories into code. Click here


Example One: Simple usage for analysis


download SimpleDocumentationSpec.cs

  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();
        }
 
    }
  }


Results output from NUnit

 
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



Example Two: Using a Narrative to execute a test


download UsingNarrativeSpec.cs
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");
        }
 
    }
}


Results output from NUnit

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



Example Three: Using an Action to execute the test


download UsingActionSpec.cs
using System;
using NUnit.Framework;
using StoryQ.Framework;
 
namespace StoryQ.Tests.Documentation
{
    [TestFixture]
    public class UsingActionsSpec
    {
 
        [Test]
        public void WritingExecutableSpecificationsAsActions()
        {
            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(() => ThatEverythingIsnt())
                    .When(() => TheTestIs_("run"))
                    .Then("the test result should be pending");
 
            //this test should pass only if an IgnoreException is throw by story.Assert()
            expectException<IgnoreException>(story.Assert);
        }
 
        static void TheTestIs_(string s)
        {
            Assert.AreEqual(s, "run");
        }
 
        static void ThatEverythingIsnt()
        {
            Assert.IsTrue(true);
        }
 
 
        static T expectException<T>(Action action) where T : Exception
        {
            try
            {
                action();
                Assert.Fail("Expected exception of type " + typeof(T).FullName);
            }
            catch (T e)
            {
                return e;
            }
            return null;
        }
 
    }
}


Results output from NUnit

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



Example Four: Complex scenario with narratives, actions and output to an html file


download ComplexScenarioWithOutputToFileSpec.cs
using System.Linq;
using System.Reflection;
using NUnit.Framework;
using StoryQ.Framework;
 
namespace StoryQ.Tests.Documentation
{
    [TestFixture]
    public class ComplexScenarioWithOutputToFileSpec
    {
        Narrative narrative;
        bool executed;
        const string aString = "LIKE THIS";
 
        [Test]
        public void WithOutputToFile()
        {
 
            Story story = new Story("implementing executable specifications");
 
            story.AsA("developer")
                .IWant("to implement executable specifications")
                .SoThat("they can show a pass or a fail")
 
                .WithScenario("converting narratives into test methods")
                    .Given(Narrative.Text("I have a written a method with a name like the narrative"))
                        .And(() => TheMethodHasntBeenRunYet())
                    .When(() => IReplaceTheStringNarrativeWithACallToTheMethod())
                       .And(() => TheTestIsRun())
                    .Then(() => TheTestOutputShouldPrintADescriptionOfThatMethod())
                        .And(() => TheMethodShouldBeExecutedAsPartOfTheTestRun())
 
 
                .WithScenario("implementing specificiations with existing method calls")
                   .Given(Narrative.Text("I don't want to use a really big name" + aString))
                        .And(() => TheMethodHasntBeenRunYet())
                    .When(Narrative.Exec("I add a method call, but leave the text there", TheTestIsRun))
                    .Then(()=>TheMethodShouldBeExecutedAsPartOfTheTestRun())
                       .And(Narrative.Exec("the narrative will go into the test output", () => 
                              Assert.AreEqual("I add a method call, but leave the text there"
                                              , story.Children.Last().Children.ElementAt(2).Narrative.Description
                                  )
                     ));
 
            story.AssertAndReportToFile(MethodBase.GetCurrentMethod());
        }
 
        private void TheTestIsRun()
        {
            narrative.Action();
        }
 
        void TheTestOutputShouldPrintADescriptionOfThatMethod()
        {
            Assert.AreEqual("Do something", narrative.Description);
        }
 
        void TheMethodShouldBeExecutedAsPartOfTheTestRun()
        {
            Assert.IsTrue(executed);
        }
 
        void TheMethodHasntBeenRunYet()
        {
            executed = false;
        }
 
        void IReplaceTheStringNarrativeWithACallToTheMethod()
        {
            narrative = new Narrative(() => DoSomething());
        }
 
        void DoSomething()
        {
            executed = true;
        }
    }
}


Results output from NUnit html here

ComplexScenarioWithOutputToFileSpec.ImplementingExecutableSpecificationsUsingActionsAndNarrativesOutputToFile : PassedStory: implementing executable specifications
 
  As a developer
  I want to implement executable specifications
  So that they can show a pass or a fail
 
  Scenario 1: converting narratives into test methods
    Given I have a written a method with a name like the narrative
      And The method hasnt been run yet                                 Passed
    When I replace the string narrative with a call to the method       Passed
      And The test is run                                               Passed
    Then The test output should print a description of that method      Passed
      And The method should be executed as part of the test run         Passed
 
  Scenario 2: implementing specificiations with existing method calls
    Given I don't want to use a really big nameLIKE THIS
      And The method hasnt been run yet                                 Passed
    When I add a method call, but leave the text there                  Passed
    Then The method should be executed as part of the test run          Passed
      And the narrative will go into the test output                    Passed
 



UI helper to convert text into C# code


Screenshot.png
Last edited Aug 18 at 9:20 PM  by toddb, version 13
Comments
No comments yet.

Updating...