This project is read-only.

How to add Variables into Scenarios

Feb 19, 2010 at 9:23 PM

Hello, I am very new to StoryQ. Is there anyone who can tell me how to convert this NBehave to StoryQ ?

I am particularly interested with the Examples portion. I think this would very useful for recurring scenarios that depends on a few variables.

Thanks in advance!


Feature: add, subtract, divide and multiply

Scenario: Add numbers
Given I have entered [num1] into the calculator
And I have entered [num2] into the calculator
When I add the numbers
Then the sum should be [result]

| 1| 2| 3|
| -1| 2| 1|
| 1| -2| -1|
| -2| -3| -5|
Feb 20, 2010 at 7:19 AM


Try the code sample below.

Let me explain more fully. StoryQ runs within a test runner - currently this is either nUnit or MSTest. Because we want storyQ
to only be an abstraction layer this means that you can use the functions of the other runners. In this case, I went and had a look at nUnits functionality
and have leveraged its Sequential feature to do the job. So, that's the basis of the code samle. Note you'll need v2.5 for this feature.

Give it a go and let me know how this works for you - here are many ways to skin this cat but I have tried to make it as close as possible to the nBehave sample.

As an aside, you may find that nBehave is better for you if you want those types of tests. We found that it was too heavy and that's why StoryQ was written. Having said
that you may even mix and match. I usually use a mix of story tests, classical unit tests and FIT/fitnesse tests in my projects - it all depends on the audience.

using NUnit.Framework;
using StoryQ;
using System.Reflection;

[Test, Sequential] public void MyTest( [Values(1,-1, 1,-2)] int num1, [Values(2, 2,-2,-3)] int num2, [Values(3, 1,-1,-5)] int result) { new Story("") .InOrderTo("") .AsA("") .IWant("") .WithScenario("Add number") .Given(IHaveEntered_intoTheCaculator, num1) .And(IHaveEntered_IntoTheCalculator, num2) .When("IAddTheNumbers") .Then(TheSumShouldBe, result) .ExecuteWithReport(MethodBase.GetCurrentMethod()); } private void IHaveEntered_intoTheCaculator(int num) { // your SUT code in each of these methods
} private void IHaveEntered_IntoTheCalculator(int num) { } private void TheSumShouldBe(int results) { }


Feb 20, 2010 at 12:05 PM

And similarly if you are using MSTest, you would just leverage it's data-driven unit testing ( Just pass the arguments from the TestContext.DataRow into your narrative methods. I recommend importing Linq to DataSets, because that gives you a nicer way to read fields off a untyped DataRow (


I think I will add these two examples to our wiki for documentation soon!