0

テストを通じていくつかのドキュメントを生成したいと考えています。これまでのところ、私のテストは次のようになります。

 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);
    }
}

残念ながら、Nunit を使用しているときは、きれいで読みやすいドキュメントを生成するために必要な情報を取得するのに苦労しています。

Nunit を使用してそれを行う人はいますか? 私がネット上で見落としていた興味深いリソースを教えていただけますか? 他のツールを使用して、テストからドキュメントを生成しますか?

[編集] 私の意図は、私のコードから次のようなものを生成することでした:

 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})

これは、最初のアプローチに適しています。後で変更するかもしれませんが、主な目標はこれです。私の目標は、上司にコードを入力させずに、上司が理解できるようなものを書けるようにすることです。

[/編集]

4

2 に答える 2

0

私は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;
}

しかし、それがどれだけ読みやすいかを述べるのはあなた次第です。

もう 1 つのオプションは、次のような SpecFlow です。

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

ドキュメントと呼ぶものに依存する場合。仕様フローは、実際にはドキュメントに非常に近いものです。

于 2012-05-03T15:37:07.463 に答える
0

NUnit を気にしないでください。リフレクションを使用してアセンブリをスキャンするだけです。テスト フィクスチャの構造は常に同じであるため、ドキュメントの生成は非常に簡単です。また、実際の値で説明的な出力を得るために、すべてのコマンドとイベントに Description() フォーマット メソッドのようなものを追加することもできます。

于 2012-05-04T07:49:51.723 に答える