TNG / JGiven

Behavior-Driven Development in plain Java
http://jgiven.org
Apache License 2.0
436 stars 99 forks source link

In the report if two parameters has the same value then they are merged in a single one. Is it normal behavior ? #160

Closed girardot closed 8 years ago

girardot commented 8 years ago

As we can see in the following report the expectedFruitType parameter has disappear in the report :

Example :

@DataProvider({
            "ORANGE, ORANGE",
            "CHERRY, CHERRY"
    })
    @Test
    public void should_display_in_report_both_parameters(final FruitType fruitType, final String expectedFruitType) {
        given().a_fruit_order_of_(fruitType)
               .with().a_quantity(12);

        when().a_fruit_order_is_mapped();

        then().the_mapped_market_order_type_is(expectedFruitType);
    }

Give the report : (without expectedFruitType)

 Scenario: should display in report both parameters

   Given a fruit order of  <fruitType>
    With a quantity 12
    When a fruit order is mapped
    Then the mapped market order type is <fruitType>

  Cases:

    | # | fruitType | Status  |
    +---+-----------+---------+
    | 1 | ORANGE    | Success |
    | 2 | CHERRY    | Success |

Working sample with two different parameters :

   @DataProvider({
            "ORANGE, ORANGES",
            "APPLE, APPLES"
    })
    @Test
    public void should_display_in_report_both_parameters(final FruitType fruitType, final String expectedFruitType) {
        given().a_fruit_order_of_(fruitType)
               .with().a_quantity(12);

        when().a_fruit_order_is_mapped();

        then().the_mapped_market_order_type_is(expectedFruitType);
    }

Give the report : (with expectedFruitType)

 Scenario: should display in report both parameters

   Given a fruit order of  <fruitType>
    With a quantity 12
    When a fruit order is mapped
    Then the mapped market order type is <expectedFruitType>

  Cases:

    | # | fruitType | expectedFruitType | Status  |
    +---+-----------+-------------------+---------+
    | 1 | ORANGE    | ORANGES           | Success |
    | 2 | APPLE     | APPLES            | Success |
janschaefer commented 8 years ago

Yes, this is expected behavior and in fact a feature of JGiven :-). The concrete parameters of the method itself are irrelevant to JGiven. JGiven instead compares all cases after all cases have been executed and derives the parameters. If two parameters are equal in all cases they are merged to a single one. This in general also what you want in practice. It is confusing IMO if you have two parameters that have the same value in all cases.