SpecFlow and complex objects

前端 未结 7 924
旧巷少年郎
旧巷少年郎 2020-12-23 17:57

I\'m evaluating SpecFlow and I\'m a bit stuck.
All samples I have found are basically with simple objects.

Project I\'m working on heavily relies on a complex ob

7条回答
  •  梦毁少年i
    2020-12-23 18:26

    I would suggest that you try to keep your scenarios as clean as possible, focusing on readability for the non-techie persons in your project. How the complex object graphs are constructed is then handled in your step definitions.

    With that said you still need a way to express hierarchical structures in your specifications, i.e. with Gherkin. As far as I know that is not possible and from this post (in the SpecFlow Google group) it seems that it has been discussed before.

    Basically you could invent a format of your own and parse that in you step. I haven't run into this myself but I think I would try a table with blank values for next level and parse that in the step definition. Like this:

    Given I have the following hierarchical structure:
    | MyObject.Id | StartDate | EndDate  | ChildObject.Id | Name | Length |
    | 1           | 20010101  | 20010201 |                |      |        |
    |             |           |          | 1              | Me   | 196    |
    |             |           |          | 2              | You  | 120    |
    

    It's not super-pretty i admit but it could work.

    Another way to do it is to use default values and just give the differences. Like this:

    Given a standard My Object with the following children:
    | Id | Name | Length |
    | 1  | Me   | 196    |
    | 2  | You  | 120    |
    

    In your step definition you then add the "standard" values for the MyObject and fill out the list of children. That approach is a bit more readable if you ask me, but you have to "know" what a standard MyObject is and how that's configured.

    Basically - Gherkin doesn't support it. But you can create a format that you can parse yourself.

    Hope this answer your question...

提交回复
热议问题