This project is read-only.

Story Title From Method Name


I like to call the method the same as the story title, i.e.:
    public void EnsureAllItemsAreSameSize()
        new Story("Ensure All Items Are Same Size")
Therefore it would be nice if there was a default Story constructor that could use the method name to determine the title.


ryzamx wrote Jun 8, 2010 at 4:57 PM

I think it's already there in Converter GUI

jegholm wrote Jun 8, 2010 at 6:34 PM

It's true that Converter GUI helps in suggesting the story title text, but it doesn't provide any constructor on the Story object.

Deducting the title from the method name, would make the code much more maintainable, as you would only have to change the method name, instead having to change the title in two places.

I actually don't use the Converter GUI, instead I use Intellisense to assist in constructing the stories.

jegholm wrote Jun 21, 2010 at 8:10 PM

Implemented the functionality described in an inheriting class:
public class UserStory : Story
    public UserStory() : base(GetTitle())

    private static string GetTitle()
        var stackTrace = new StackTrace();
        StackFrame frame = stackTrace.GetFrame(2);
        MethodBase method = frame.GetMethod();
        string name = method.Name;
        string title = name.Wordify(); // Extension method that Converts Pascal Cased string into separate words
        return title;

bronumski wrote May 21, 2011 at 12:44 AM

I am also after something like this but I would like to use the fixture (class) name as the Story name and the test name as the scenario. What I do at the moment:

public class When_adding
Feature story = new Story("When adding")...;

public void Should_add_two_positive_numbers()
store.WithSenario("Should add two positive numbers")...;

public void Should_add_two_negative_numbers()
store.WithSenario("Should add two negative numbers")...;