0

i have set up a parameterized test as per the example on this page:
https://mkyong.com/unittest/junit-4-tutorial-6-parameterized-test/

i also had a read of this question: Loop through array, each element a JUnit test and looked at the other sites

in mkyoung's example, the public static Collection<Object[]> data() { method is returning an Array and creating a new object. i have tried to replicate this but am having trouble.

i have the @RunWith annotation, have created the test class, and passed the parameters into the constructor. but the issue lies with the test itself. i'm having trouble with what to pass in the return statement. i think the testData.account part is correct (maybe lol) because it returns a list, but the bit im stuck on it creating an object for the test data to "sit in".

Here's what i have so far.

@RunWith(value = Parameterized.class)

public class BuildAccountDataTest {
    private final String accountNumber;
    private final String expectedAccountNumber;
    private final String accountType;
    private final String expectedAccountType;

    public BuildAccountDataTest(String accountNumber, String expectedAccountNumber, String accountType, String expectedAccountType) throws IOException {
        this.accountNumber = accountNumber;
        this.expectedAccountNumber = expectedAccountNumber;
        this.accountType = accountType;
        this.expectedAccountType = expectedAccountType;
    }


    @Parameters
    public static List<Account> data() throws IOException {

        ObjectMapper mapper = new ObjectMapper();
        File testDataFile = new File(BuildAccountDataTest.class.getClassLoader().getResource("testDataForKafka").getFile());

        EntireCard testData = mapper.readValue(testDataFile, EntireCard.class);

        Account a = new Account();

        // return testData.account;  // this gives us all the accounts in the file as a list? i think

        return testData.account.stream(new Object [][]{

        }

//        return List.of(a new Object [][]{
//            { 0, "5402231036194884   "}
//
//            ;
//
//        }

    }
Kath
  • 1
  • 1

0 Answers0