r/java • • Jun 01 '24

What java technology (library, framework, feature) would not recommend and why?

165 Upvotes

464 comments sorted by

View all comments

4

u/DelayLucky Jun 01 '24 edited Jun 01 '24

The table-driven test idiom.

Is it really more readable to have a magnificent table of cryptic test parameters:

"hasSchema: false, hasData: true, inputData: abc, expectedToThrow: false, expectedMessage: '', expectedResult: foo",
"hasSchema: true, hasData: false, inputData: null, expectedToThrow: true, expectedMessage: 'badbad'",
"hasSchema: false, hasData: false, inputData: null, expectedToThrow: false, expectedMessage: '', expectedResult: bar",

Compared to plain-old prose-like tests?

public void testNoSchema_withData_returnsGoodResult() {
  Input input = Input.newBuilder()
      .setData("abc")
      .build();
  assertThat(runSut(input)).isEqualTo("foo");
}

Sure, it'll take more lines, but programming is about readability, and is not about who can come up with a clever compression algorithm to save the linebreak characters.

1

u/xfel11 Jun 02 '24

Depends on how many lines my test has vs how many parameters it needs.

→ More replies (1)