0

I have a junit test method which i test against the parameterized generated data sets

@Parameterized.Parameters
public static Collection primeNumbers() {
    return Arrays.asList(new Object[][] {
         { readRequestFile(reqFile1), readResponseFile(resFile1)},
         { readRequestFile(reqFile2), readResponseFile(resFile2)},
         { readRequestFile(reqFile3), readResponseFile(resFile3)}
    });
}

As in above code the data sets are hard coded, i have a directory where the files are present i want to load these files in test data set dyamically something like

<!-- language: lang-java -->



 @Parameterized.Parameters
    public static Collection primeNumbers () {
        return Arrays.asList(new Object[][] {
                    listOfRequestFiles = readAllRequestFilesFromTheResourceDirecotry
                    listOfResponseFiles = readAllResponseFilesFromTheResourceDirecotry

//lets say i read files from somewhere
listOfFiles = getAllfiles();
for (filename: listOfFiles) {
                //by some way this files should be available for testing data
            }
        });
    }

How can this be achieved , can somebody help

Tayab Hussain
  • 831
  • 9
  • 16
  • If you could switch to junit5, there is something like TestFactory, maybe it could be useful for you https://www.baeldung.com/junit5-dynamic-tests – staszko032 Oct 02 '18 at 15:01
  • I guess the TestFactory is for dynamic test cases, but in my case i am looking for generation of test data dynamically – Tayab Hussain Oct 02 '18 at 16:27
  • I would like to help you, but I don't understand the second code snippet. Can you add some types so that it is more clear what you try to achieve. – Stefan Birkner Oct 03 '18 at 10:19

0 Answers0