Running Specs from your IDE Edit on GitHub


There will be a "dotnet test" adapter for Storyteller in the VS 2017 timeframe that will make the following samples mostly unnecessary, but we're waiting for more VS 2017 adoption and stabilization.

Storyteller specifications will fail and there will be times when you're really going to want to be able to debug through your code while a Storyteller specification is running. While you can always attach a debugger to the running system under test when the Storyteller UI is running, it's a faster feedback cycle to be able to just start and run your specification from whatever IDE you are using.

Run Single Spec in Storyteller 5.0

If you're developing with Visual Studio.Net or JetBrains Rider, you can pass the full path of the specification copied from the Specification editor and use that as an argument to the console app to run a single specification or suite:

dotnet run -- run "suite / specification"

Do note that the specification path can accept spaces around the "/" characters, so you can copy and paste the specification path directly from the specification editor.

StorytellerRunner

In all cases, the code shown in this topic must be contained within your Storyteller specification project.

To that end, Storyteller 4.1 (re)introduces the StorytellerRunner class that you can use to execute Storyteller specifications from the IDE. If your Storyteller specification project does not have any kind of custom ISystem (i.e., you kick it off with StorytellerAgent.Run(args)), you can use this syntax:


public void run_spec()
{
    // There is an optional argument in this method to give
    // Storyteller a hint about where the project root folder
    // is, but in most cases it should be able to figure that
    // out on its own
    using (var runner = StorytellerRunner.Basic())
    {
        // run one spec by its path as shown in the UI.
        // You can just copy/paste the full spec path
        // from the spec editor page in the UI
        var results = runner.Run("Arrays / Use an array argument");
        Console.WriteLine(results.Counts);

        // You can open the results in a browser window
        runner.OpenResultsInBrowser();

        // You can write the results to a file
        runner.WriteResultsDocument("results.htm");

        // Run all the specifications in the project
        runner.RunAll(TimeSpan.FromMinutes(2));
    }
}

I use the venerable TestDriven.Net tool to run unit tests inside of Visual Studio.Net. One of its nifty features is the ability to run any arbitrary method in your code as well as run the method in the debugger. You may instead opt to add a unit testing tool like xUnit and kick off Storyteller specifications from a unit test where you have many more options for running the code.

If you are using a custom ISystem, use the syntax shown below to bootstrap the runner:


public static void Debug()
{
    using (var runner = StorytellerRunner.For<SpecificationSystem>())
    {
        runner.Run("path to the spec");
    }
}