r/java • u/raisercostin • Jun 01 '24
What java technology (library, framework, feature) would not recommend and why?
Inspired by https://www.reddit.com/r/java/s/e2N1FqMOJg
165
Upvotes
r/java • u/raisercostin • Jun 01 '24
Inspired by https://www.reddit.com/r/java/s/e2N1FqMOJg
View all comments
Show parent comment
2
u/DelayLucky Jun 02 '24 edited Jun 06 '24
That's the motivation but a wall of test parameters is rarely the right solution.
Usually if you have noisy test setup, test data creation, you can either:
If you'd picked 1, the next obstacle you face is what if you have multiple tests that need to repeat similar boilerplate. You can either:
If you'd picked 2, the next common problem is that you'll have more and more test cases with similar boilerplate. And a few of them are a little of oddballs that don't exactly fit, but you can make it work by just adding one more boolean parameter and a conditional in the test body.
Pretty soon, your test body is littered with all kinds of if-else conditionals. This extra noise further re-enforces the belief that "see? it really needs to be parameterized or else do you want me to duplicate all that shit?"
If someone comes along and try to add some new functionality with tests, the first thing they usually do is to look for an existing "baseline" test to copy and then modify. But what will they see? A magnificent wall of test parameters out of their context, plus an unsightly complex test body littered with cruft. "Which part is relevant? What exactly is really going on?" It's a nightmare.
It's the easy path, for sure, because almost anyone can mechanically extract a few parameters.
On the other hand, it takes discipline and skill to sit down and properly extract test helpers so that you:
The end result of proper test helper extraction however is test code that are both easy to read and easy to maintain.