|
| 1 | +--- |
| 2 | +name: migrate-junit-source-to-tabletest |
| 3 | +description: Convert JUnit 5 @MethodSource/@CsvSource/@ValueSource parameterized tests to @TableTest (JDK8) |
| 4 | +--- |
| 5 | +Goal: Migrate JUnit 5 parameterized tests using @MethodSource/@CsvSource/@ValueSource to @TableTest with minimal churn and passing tests. |
| 6 | + |
| 7 | +Process (do in this order): |
| 8 | +1) Locate targets via Grep (no agent subprocess). Search for: "@ParameterizedTest", "@MethodSource", "@CsvSource", "@ValueSource". |
| 9 | +2) Read all matching files up front (parallel is OK). |
| 10 | +3) Convert eligible tests to @TableTest. |
| 11 | +4) Write each modified file once in full using Write (no incremental per-test edits). |
| 12 | +5) Run module tests once and verify "BUILD SUCCESSFUL". If failed, inspect JUnit XML report. |
| 13 | + |
| 14 | +Dependency: |
| 15 | +- If missing, add: |
| 16 | + - Groovy: testImplementation libs.tabletest |
| 17 | + - Kotlin: testImplementation(libs.tabletest) |
| 18 | + |
| 19 | +Import: `import org.tabletest.junit.TableTest;` |
| 20 | + |
| 21 | +JDK 8 rules: |
| 22 | +- No text blocks. |
| 23 | +- @TableTest must use String[] annotation array syntax: |
| 24 | + ``` |
| 25 | + @TableTest({ |
| 26 | + "a | b", |
| 27 | + "1 | 2" |
| 28 | + }) |
| 29 | + ``` |
| 30 | + |
| 31 | +Table formatting rules (mandatory): |
| 32 | +- Always include a header row (parameter names). |
| 33 | +- Always add a "scenario" column; using common sense for naming; scenario is NOT a method parameter. |
| 34 | +- Use '|' as delimiter. |
| 35 | +- Align columns with spaces so pipes line up vertically. |
| 36 | +- Prefer single quotes for strings requiring quotes (e.g., 'a|b', '[]', '{}', ' '). |
| 37 | + |
| 38 | +Conversions: |
| 39 | +A) @CsvSource |
| 40 | +- Remove @ParameterizedTest and @CsvSource. |
| 41 | +- If delimiter is '|': rows map directly to @TableTest. |
| 42 | +- If delimiter is ',' (default): replace ',' with '|' in rows. |
| 43 | + |
| 44 | +B) @ValueSource |
| 45 | +- Convert to @TableTest with header from parameter name. |
| 46 | +- Each value becomes one row. |
| 47 | +- Add "scenario" column using common sense for name. |
| 48 | + |
| 49 | +C) @MethodSource (convert only if values are representable as strings) |
| 50 | +- Convert when argument values are primitives, strings, enums, booleans, nulls, and simple collection literals supported by TableTest: |
| 51 | + - Array: [a, b, ...] |
| 52 | + - List: [a, b, ...] |
| 53 | + - Set: {a, b, ...} |
| 54 | + - Map: [k: v, ...] |
| 55 | +- `@TableTest` and `@MethodSource` may be combined on the same `@ParameterizedTest` when most cases are tabular but a few cases require programmatic setup. |
| 56 | +- In combined mode, keep table-friendly cases in `@TableTest`, and put only non-tabular/complex cases in `@MethodSource`. |
| 57 | +- If `@TableTest` is not viable for the test at all, use `@MethodSource` only. |
| 58 | +- For `@MethodSource`, name the arguments method `<testMethodName>Arguments` (camelCase, e.g. `testMethodArguments`) and return `Stream<Arguments>` using `Stream.of(...)` and `arguments(...)` with static import. |
| 59 | +- Blank cell = null (non-primitive). |
| 60 | +- '' = empty string. |
| 61 | +- For String params that start with '[' or '{', quote to avoid collection parsing (prefer '[]'/'{}'). |
| 62 | + |
| 63 | +Scenario handling: |
| 64 | +- 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. |
| 65 | + |
| 66 | +Cleanup: |
| 67 | +- Delete now-unused @MethodSource provider methods and unused imports. |
| 68 | + |
| 69 | +Mixed eligibility: |
| 70 | +- Prefer combining `@TableTest` + `@MethodSource` on one `@ParameterizedTest` when only some cases are complex. |
| 71 | + |
| 72 | +Do NOT convert when: |
| 73 | +- Most rows require complex builders/mocks. |
| 74 | + |
| 75 | +Test command (exact): |
| 76 | +./gradlew :path:to:module:test --rerun-tasks 2>&1 | tail -20 |
| 77 | +- If BUILD FAILED: cat path/to/module/build/test-results/test/TEST-*.xml |
0 commit comments