How to write JGiven parameterized scenario (JUnit5) with multiple sources?

137 Views Asked by At

I use JGiven with JUnit 5 and have to implement a parameterized test using two CSV files as sources. The first CSV file contains the actual input, the second contains the expected output.

Using the docs I ended up with something like this:

@ExtendWith(JGivenExtension.class)
public class TestCase extends ScenarioTest<TGiven, TWhen, TThen> {

  @ParameterizedTest
  @ArgumentsSource(MyArgumentsProvider.class)
  public void test_something(MyObject obj) {
    given().the_input_from_file("input.csv");
    when().doing_some_stuff_with_data_from_input_file();
    then().the_result_should_match(obj);
  }
}

The MyArgumentsProvider loads the second CSV file and parses objects from it (MyObject).

Now the problem is, for every obj argument the input.csv is loaded/parsed. To avoid that i put the parsing of the input.csv to a @BeforeAll method and pass the required objects generated from it to the TGiven stage via given().the_input_data(parsedListOfInputData).

But now, i need to provide this objects to the TWhenstage. This doesn't work.

Meanwhile i think, this is not the right approach here, but i can't find another solution. Any hints to make this work? Thx

0

There are 0 best solutions below