I use the below to access a csv file in my paramaterized JUnit5 test but is there any way to dynamically provide this csv file or a different file path to the location of the csv file?
@CsvFileSource(resources = "/testDataFile/testData.csv" , numLinesToSkip = 1, delimiter = ';', encoding = "UTF-8")
In other words can I dynamically update "/testDataFile/testData.csv"?
I want a way to dynamically pass in the file path for my csv file so it is not a hardcoded location or file name.
I'm afraid this is not possible. In general, the value for an annotation must be a constant expression. And the
@CsvFileSourceAPI doesn't support dynamic/programmatic control over the supplied value(s), at least to my knowledge.Two possible custom solutions:
Create an
@ArgumentsSourceand a correspondingArgumentsProvider, based onCsvArgumentsProvider(which is non-public).Create an extension that dynamically creates the CSV file(s) specified as
resources/filesin@CsvFileSource.