3
Vote

Story Title From Method Name

description

I like to call the method the same as the story title, i.e.:
    [TestMethod]
    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.

comments

ryzamx wrote Jun 8, 2010 at 3:57 PM

I think it's already there in Converter GUI

jegholm wrote Jun 8, 2010 at 5: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 7: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 20, 2011 at 11:44 PM

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:

[TestFixture]
public class When_adding
{
Feature story = new Story("When adding")...;

[Test]
public void Should_add_two_positive_numbers()
{
store.WithSenario("Should add two positive numbers")...;
}

[Test]
public void Should_add_two_negative_numbers()
{
store.WithSenario("Should add two negative numbers")...;
}

}