Goal: Migrate JUnit 5 parameterized tests using @MethodSource/@CsvSource/@ValueSource to @TableTest with minimal churn and passing tests.
Process (do in this order):
- Locate targets via Grep (no agent subprocess). Search for: "@ParameterizedTest", "@MethodSource", "@CsvSource", "@ValueSource".
- Read all matching files up front (parallel is OK).
- Convert eligible tests to @TableTest.
- Write each modified file once in full using Write (no incremental per-test edits).
- Run module tests once and verify "BUILD SUCCESSFUL". If failed, inspect JUnit XML report.
Import: import org.tabletest.junit.TableTest;
JDK 8 rules:
Table formatting rules (mandatory):
- Always include a header row (parameter names).
- Always add a "scenario" column; using common sense for naming; scenario is NOT a method parameter.
- Use '|' as delimiter.
- Align columns with spaces so pipes line up vertically.
- Prefer single quotes for strings requiring quotes (e.g., 'a|b', '[]', '{}', ' ').
- Use value sets (
{a, b, c}) instead of matrix-style repetition when only one dimension varies across otherwise-identical rows.
Conversions:
A) @CsvSource
- Remove @ParameterizedTest and @CsvSource.
- If delimiter is '|': rows map directly to @TableTest.
- If delimiter is ',' (default): replace ',' with '|' in rows.
B) @ValueSource
- Keep single-parameter tests on
@ValueSource (and @NullSource when null cases are needed).
- Otherwise convert to @TableTest with header from parameter name.
- Each value becomes one row.
- Add "scenario" column using common sense for name.
C) @MethodSource (convert only if values are representable as strings)
- Convert when argument values are primitives, strings, enums, booleans, nulls, and simple collection literals supported by TableTest:
- Array: [a, b, ...]
- List: [a, b, ...]
- Set: {a, b, ...}
- Map: [k: v, ...]
@TableTest and @MethodSource may be combined on the same @ParameterizedTest when most cases are tabular but a few cases require programmatic setup.
- In combined mode, keep table-friendly cases in
@TableTest, and put only non-tabular/complex cases in @MethodSource.
- If
@TableTest is not viable for the test at all, use @MethodSource only.
- For
@MethodSource, name the arguments method <testMethodName>Arguments (camelCase, e.g. testMethodArguments) and return Stream<Arguments> using Stream.of(...) and arguments(...) with static import.
- Blank cell = null (non-primitive).
- '' = empty string.
- For String params that start with '[' or '{', quote to avoid collection parsing (prefer '[]'/'{}').
D) @TypeConverter
- Use
@TypeConverter for symbolic constants used by migrated table rows (e.g. Long.MAX_VALUE, DDSpanId.MAX).
- Prefer explicit one-case-one-return mappings.
- Prefer shared converter utilities (e.g. in
utils/test-utils) when reuse across modules is likely.
Scenario handling:
- If MethodSource includes a leading description string OR @ParameterizedTest(name=...) uses {0}, convert that to a scenario column and remove that parameter from method signature.
Cleanup:
- Delete now-unused @MethodSource provider methods and unused imports.
Mixed eligibility:
- Prefer combining
@TableTest + @MethodSource on one @ParameterizedTest when only some cases are complex.
Do NOT convert when:
- Most rows require complex builders/mocks.
Test command (exact):
./gradlew :path:to:module:test --rerun-tasks 2>&1 | tail -20
- If BUILD FAILED: cat path/to/module/build/test-results/test/TEST-*.xml
Source: DataDog/dd-trace-java — distributed by TomeVault.
1---2name: migrate-junit-source-to-tabletest3description: Convert JUnit 5 @MethodSource/@CsvSource/@ValueSource parameterized tests to @TableTest (JDK8) Use when this capability is needed.4---5Goal: Migrate JUnit 5 parameterized tests using @MethodSource/@CsvSource/@ValueSource to @TableTest with minimal churn and passing tests.67Process (do in this order):81) Locate targets via Grep (no agent subprocess). Search for: "@ParameterizedTest", "@MethodSource", "@CsvSource", "@ValueSource".92) Read all matching files up front (parallel is OK).103) Convert eligible tests to @TableTest.114) Write each modified file once in full using Write (no incremental per-test edits).125) Run module tests once and verify "BUILD SUCCESSFUL". If failed, inspect JUnit XML report.1314Import: `import org.tabletest.junit.TableTest;`1516JDK 8 rules:17- No text blocks.18- @TableTest must use String[] annotation array syntax:19 ```20 @TableTest({21 "a | b",22 "1 | 2"23 })24 ```2526Table formatting rules (mandatory):27- Always include a header row (parameter names).28- Always add a "scenario" column; using common sense for naming; scenario is NOT a method parameter.29- Use '|' as delimiter.30- Align columns with spaces so pipes line up vertically.31- Prefer single quotes for strings requiring quotes (e.g., 'a|b', '[]', '{}', ' ').32- Use value sets (`{a, b, c}`) instead of matrix-style repetition when only one dimension varies across otherwise-identical rows.3334Conversions:35A) @CsvSource36- Remove @ParameterizedTest and @CsvSource.37- If delimiter is '|': rows map directly to @TableTest.38- If delimiter is ',' (default): replace ',' with '|' in rows.3940B) @ValueSource41- Keep single-parameter tests on `@ValueSource` (and `@NullSource` when null cases are needed).42- Otherwise convert to @TableTest with header from parameter name.43- Each value becomes one row.44- Add "scenario" column using common sense for name.4546C) @MethodSource (convert only if values are representable as strings)47- Convert when argument values are primitives, strings, enums, booleans, nulls, and simple collection literals supported by TableTest:48 - Array: [a, b, ...]49 - List: [a, b, ...]50 - Set: {a, b, ...}51 - Map: [k: v, ...]52- `@TableTest` and `@MethodSource` may be combined on the same `@ParameterizedTest` when most cases are tabular but a few cases require programmatic setup.53- In combined mode, keep table-friendly cases in `@TableTest`, and put only non-tabular/complex cases in `@MethodSource`.54- If `@TableTest` is not viable for the test at all, use `@MethodSource` only.55- For `@MethodSource`, name the arguments method `<testMethodName>Arguments` (camelCase, e.g. `testMethodArguments`) and return `Stream<Arguments>` using `Stream.of(...)` and `arguments(...)` with static import.56- Blank cell = null (non-primitive).57- '' = empty string.58- For String params that start with '[' or '{', quote to avoid collection parsing (prefer '[]'/'{}').5960D) @TypeConverter61- Use `@TypeConverter` for symbolic constants used by migrated table rows (e.g. `Long.MAX_VALUE`, `DDSpanId.MAX`).62- Prefer explicit one-case-one-return mappings.63- Prefer shared converter utilities (e.g. in `utils/test-utils`) when reuse across modules is likely.6465Scenario handling:66- If MethodSource includes a leading description string OR @ParameterizedTest(name=...) uses {0}, convert that to a scenario column and remove that parameter from method signature.6768Cleanup:69- Delete now-unused @MethodSource provider methods and unused imports.7071Mixed eligibility:72- Prefer combining `@TableTest` + `@MethodSource` on one `@ParameterizedTest` when only some cases are complex.7374Do NOT convert when:75- Most rows require complex builders/mocks.7677Test command (exact):78./gradlew :path:to:module:test --rerun-tasks 2>&1 | tail -2079- If BUILD FAILED: cat path/to/module/build/test-results/test/TEST-*.xml8081---82> Source: [DataDog/dd-trace-java](https://github.com/DataDog/dd-trace-java) — distributed by [TomeVault](https://tomevault.io).83<!-- tomevault:4.0:skill_md:2026-07-03 -->