vendredi 27 juillet 2018

Passing JSON file as source to JUnit test case

I have a dataset stored in a JSON file. Is there any way to pass that json to JUnit test case.

Taking @CSVFileSource as reference I am looking for something like this.

@ParameterizedTest
@CsvFileSource(resources = "/input_file.json")
void testWithCsvFileSource(String expected_output, String input_date, String output_format, String default_value, String exception_handling) {
           assertEquals(expected_output, myLogic(input_date,output_format,default_value,exception_handling));
}

Sample Json

    {
"1":{
    "expected_output": "bad_date",
    "input_date": "112321",
    "output_format": "",
    "default_value": "",
    "exception_handling": ""
},
"2":{
    "expected_output": "bad_date",
    "input_date": "112322",
    "output_format": "",
    "default_value": "",
    "exception_handling": ""
},
"3":{
    "expected_output": "bad_date",
    "input_date": "112323",
    "output_format": "",
    "default_value": "",
    "exception_handling": ""
},
"4":{
    "expected_output": "bad_date",
    "input_date": "112324",
    "output_format": "",
    "default_value": "",
    "exception_handling": ""
}
}

Aucun commentaire:

Enregistrer un commentaire