0

I am willing to generate some documentation through my test. So far my test look like this :

 public class creation_of_a_new_inventory_item : BaseClass<CreateInventoryItem>
    {
    private Guid _Id = Guid.NewGuid();
    private string _Name = "test";

    public override CommandHandler<CreateInventoryItem> OnHandle(IRepository repository)
    {
        return  new CreateInventoryItemHandler(repository);
    }

    protected override IEnumerable<IEvent> Given()
    {
        yield break;
    }

    protected override CreateInventoryItem When()
    {
        return new CreateInventoryItem()
        {
            Id = _Id,
            Name = _Name
        };
    }

    protected override IEnumerable<IEvent> Expect()
    {
        yield return new InventoryItemCreatedAdded()
                         {
                             Id = _Id,
                             Name = _Name
                         };
    }

   [Test]
    public void does_not_throw_an_Exception()
    {
        Assert.IsNull(Caught);
    }
}

Unfortunately, when using Nunit, I struggle at getting the informations I need in order to generate some pretty and easy to read documentation.

Is there any of you using Nunit to do that? Could you point me some interesting resource, I would have overlooked on the net? Do you generate documentation out of your test using other tools?

[edit] My intent was to produce outof my code something like this :

 creation of a new inventory item
     When I Create Inventory Item 
        Id:{id},
        Name:{name}
     Then 
         Inventory Item is Created ({Success/Fail})
             Id:{id},
             Name:{name} 
     And does not throw an Exception ({Success/Fail})

This would do for a first approach. I might change things later, but the main goal would be this. My aim is to be able to write something my boss might understand without letting him enter the code.

[/edit]

Arthis
  • 2,283
  • 21
  • 32
  • What are you using to "Generate documentation"? – Peter Ritchie May 03 '12 at 15:47
  • At first I intended to use a Nunit plugin with eventlistenner in order to get the result of my test. But I got stucked with too many dependances from my project on this plug in, so I was wondering about finding a better approach... – Arthis May 03 '12 at 15:54

2 Answers2

0

I got something like this in Documently:

[Subject(typeof(Customer))]
public class When_customer_relocates
    : Handler_and_Aggregate_spec
{
    static NewId AggregateId = NewId.Next();

    static RelocateTheCustomerHandler handler;

    Establish context = () =>
        {
            setup_repository_for<Customer>();
            has_seen_events<Customer>(CustomerTestFactory.Registered(AggregateId));
            handler = new RelocateTheCustomerHandler(() => repo);
        };

    Because of = () =>
        handler.Consume(a_command<RelocateTheCustomer>(new MsgImpl.Relocate
            {
                AggregateId = AggregateId,
                NewAddress = new MsgImpl.Address
                    {
                        City = "Berlin",
                        PostalCode = "4566",
                        Street = "FünfteStrasse",
                        StreetNumber = 45
                    },
                Version = 1U
            }));

    It should_have_loaded_existing = () =>
        A.CallTo(() => repo.GetById<Customer>(AggregateId, 1)).MustHaveHappened(Repeated.Exactly.Once);

    It should_have_published_relocated_event = () => 
        yieldedEvents.ShouldContain<Relocated>(
            r => r.City.ShouldEqual("Berlin"));

    Behaves_like<Event_versions_are_greater_than_zero> should_specify_versions_above_zero;
    Behaves_like<Event_versions_are_monotonically_increasing> should_specify_monotonically_increasing_versions;
    Behaves_like<Events_has_non_default_aggregate_root_id> should_have_non_default_ar_ids;
}

But it's up to you to state how readable you find it.

Another option for you might be SpecFlow, looking like this:

Feature: Score Calculation 
  In order to know my performance
  As a player
  I want the system to calculate my total score

Scenario: Gutter game
  Given a new bowling game
  When all of my balls are landing in the gutter
  Then my total score should be 0

Scenario: Beginners game
  Given a new bowling game
  When I roll 2 and 7
  And I roll 3 and 4
  And I roll 8 times 1 and 1
  Then my total score should be 32

Scenario: Another beginners game
  Given a new bowling game
  When I roll the following series: 2,7,3,4,1,1,5,1,1,1,1,1,1,1,1,1,1,1,5,1
  Then my total score should be 40

Scenario: All Strikes
  Given a new bowling game
  When all of my rolls are strikes
  Then my total score should be 300

Scenario: One single spare
   Given a new bowling game 
   When I roll the following series: 2,8,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1
   Then my total score should be 29

Scenario: All spares
  Given a new bowling game
  When I roll 10 times 1 and 9
  And I roll 1
  Then my total score should be 110

If depends on what you call documentation; spec flow is really close to documentation actually.

Henrik
  • 9,714
  • 5
  • 53
  • 87
  • thx Henrik, I will have a look at how things are done in Documently. It might give me some good idea on how to proceed. – Arthis May 03 '12 at 16:10
0

Don't bother with NUnit. Just scan you assembly using reflection. The structure of you test fixture will alway be the same, so it extremely easy to generate documentation. Also you can add smth like Description() formatting method to all of your Commands and Events, in order to get descriptive output with actual values.

Yevhen Bobrov
  • 696
  • 4
  • 11