Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add possibility to define test-case name #139

Closed
Rubbiroid opened this issue Oct 7, 2015 · 10 comments
Closed

Add possibility to define test-case name #139

Rubbiroid opened this issue Oct 7, 2015 · 10 comments

Comments

@Rubbiroid
Copy link
Contributor

Hi,

if you use JGiven use dataprovider to supply test cases, you may want to have a test-case description. Right now it can be done by calling an own method like given().the_test_case_is( description ), which is not a good solution IMHO.
Can you please provide a possibility to define a description of a test case? E.g. via special annotation of a test function argument.

Best regards,
Pavel

@janschaefer
Copy link
Contributor

This goes into a similar direction as #134 and is actually a generalization of it.

@janschaefer
Copy link
Contributor

@nikowitt this feature is now implemented. It would be cool if you could shortly test it on your side and tell me what you think. You use the feature by adding the @CaseDescription annotation to the test method. With the value of the annotation you can specify the description. You can use the placeholders to insert parameter values. In the following example, I provide an additional value that is the description of the scenario and use the placeholder $0 to refer to that description:

@Test
@DataProvider( {
      "This is the first case, true",
      "This is another case, false"
} )
@CaseDescription( "$0" )
public void custom_descriptions_of_cases_appear_as_a_separate_column_in_the_data_table(  
              String description, boolean value ) {
        given().the_power_light_$_on( value );
}

The feature is included in version 0.9.2-SNAPSHOT

janschaefer pushed a commit that referenced this issue Oct 9, 2015
@nikowitt
Copy link
Contributor

nikowitt commented Oct 9, 2015

Sounds really cool - I will test this on Tuesday when I return to the office ☺

Am 9. Oktober 2015 17:09:48 MESZ, schrieb Jan notifications@github.com:

@nikowitt this feature is now implemented. It would be cool if you
could shortly test it on your side and tell me what you think. You use
the feature by adding the ~@CaseDescriptionannotation to the test method. With the value of the annotation you can specify the description. You can use the placeholders to insert parameter values. In the following example, I provide an additional value that is the description of the scenario and use the placeholder$0` to refer to
that description:

@Test
@DataProvider( {
     "This is the first case, true",
     "This is another case, false"
} )
@CaseDescription( "$0" )
public void
custom_descriptions_of_cases_appear_as_a_separate_column_in_the_data_table(

             String description, boolean value ) {
       given().the_power_light_$_on( value );
}

Reply to this email directly or view it on GitHub:
#139 (comment)

@janschaefer
Copy link
Contributor

Sure :-)

@nikowitt
Copy link
Contributor

OK, I've just tested it - it's pretty fine for my cases. Something that is worth discussing is what happens if @CaseDescription is used and no @dataProvider is used. In this case, I expect the description to be displayed somewhere in my report even though it actually makes no sense to use the @CaseDescription here.

@nikowitt
Copy link
Contributor

Some more feedback: In our history test, we want e.g. to include the return type of the field to be tested. The @dataProvider only contains the name of the field, but the actual type is determined at test runtime. Maybe it is also possible to be able to reference test scenario variables in @CaseDescription? When I create a dummy variable and assign the value at runtime, it is still considered null.

@janschaefer
Copy link
Contributor

Mmh, I do not completely understand that. What do you mean by scenario variables? Could you make a short example?

@nikowitt
Copy link
Contributor

Sure:

    @Test
    @DataProvider({
            "Supplier" + _ + Supplier.NOTES,
            "Supplier" + _ + Supplier.STATUS
    })
    @CaseDescription("updating field '$1'")
    public void test_log_history_entries(Class<? extends Base<?>> typeOfEntity, String fieldName) throws Exception {


        given().entity_of_$(typeOfEntity)
                .and().logged_in_system_user();

        // TODO: restore return type in description!
        String returnType = SumaHistoryTestSteps.getReturnType();
        when().user_updates_entity(fieldName);

        then().log_history_entry_is_created(fieldName)
                .and().log_history_displays_correct_values(fieldName, null);
    }

The issue why I cannot provide -SumaHistoryTestSteps.getReturnType();- in the DataProvider is that for doing so, the Spring context is required, but not provided yet, so the value can only be calculated in the scenario itself.

@janschaefer
Copy link
Contributor

I think in this case it should be possible to do the following:

 @CaseDescription( provider = CustomCaseDescriptionProvider.class )
...

static class CustomCaseDescriptionProvider implements CaseDescriptionProvider {

   public String description( String value, List<String> parameterNames, List<?> parameterValues ) {
       return "updating field "+parameterValues.get(1)+" type = " + SumaHistoryTestSteps.getReturnType();    
   }
}

does that work?

@nikowitt
Copy link
Contributor

Yes, works perfectly :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants