refactor(tests): Use @ParameterizedTest instead of looping over test data#1405
Conversation
@ParameterizedTest instead of looping over test data
74f0d9d to
46f56bf
Compare
|
I took another look at this, and I'm now hesitant to merge it. The parameterization doesn't seem to give us much benefit here:
Overall, this feels like a step backward in readability and maintainability. I'm not convinced the migration to @rubenporras WDYT? |
Code reduction was not the goal here. I prefer parameterized tests over regular tests with loops because the former gives you much better test feedback. Imagine if the test fails for 3 out of 10 inputs. With the current setup, the test would fail with the first invalid input and you don't know if it fails for any other inputs. With parameterized tests you would immediately see which inputs have failed, because they are all executed, regardless of whether another test input has generated an error.
Fair point, but that just the design of parameterized tests in JUnit. I usually place the test data right above the test method and give both the same name, which I think is not too bad for readability.
We can use the existing record instead of |
That is a good argument.
Yes I would prefer the type-safe record but I also would not like to have it visible to the other test methods. I think the problem here is that the test class is too large. Maybe if the parameterized tests should live in a dedicated test class with a single test method. then it doesn't matter to have the parameters in a static field and having a record for the parameters. Let's wait what @rubenporras has to say. |
|
Thanks for the idea of using parameterized test now that you upgraded to JUnit 5 and providing the implementation. I did not know the feature at all. For me, since this is a test class, as long as the test runs nicely, I would be fine with the current implementation or having the type-safe record (in this on a new dedicated class). For me I would merge as it is. If @sebthom prefers the test in its own class so that we can have the record, I would also go along. @sebthom: do you think the extra round on the PR is worth it? If so, I would suggest we aim for that. |
Followup to #1403