You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Sample usage of `@TableTest`.
feat(json): Improve tests
Merge branch 'master' into alexeyk/table-test-example
Merge remote-tracking branch 'origin/bbujon/json-tests' into alexeyk/table-test-example
Apply changes from review
Minor
Improved skills
Renamed skill
Minor skills cleanup
Minor skills cleanup
Merge branch 'master' into alexeyk/table-test-example
Workaround for build error on CI: `zip END header not found`.
Merge branch 'master' into alexeyk/table-test-example
Co-authored-by: PerfectSlayer <bruce.bujon@datadoghq.com>
Co-authored-by: alexey.kuznetsov <alexey.kuznetsov@datadoghq.com>
Copy file name to clipboardExpand all lines: .claude/skills/migrate-groovy-to-java/SKILL.md
+37-2Lines changed: 37 additions & 2 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -16,8 +16,11 @@ Migrate test Groovy files to Java using JUnit 5
16
16
17
17
When converting Groovy code to Java code, make sure that:
18
18
- The Java code generated is compatible with JDK 8
19
-
- When translating Spock tests, favor using `@CsvSource` with `|` delimiters
20
-
- When using `@MethodSource`, name the arguments method by appending `Arguments` using camelCase to the test method name (e.g. `testMethodArguments`) and return a `Stream` of arguments using `Stream.of(...)` and `arguments(...)` with static import.
19
+
- When translating Spock tests, prefer `@TableTest` for data rows that are naturally tabular. See detailed guidance in the "TableTest usage" section.
20
+
-`@TableTest` and `@MethodSource` may be combined on the same `@ParameterizedTest` when most cases are tabular but a few cases require programmatic setup.
21
+
- In combined mode, keep table-friendly cases in `@TableTest`, and put only non-tabular/complex cases in `@MethodSource`.
22
+
- If `@TableTest` is not viable for the test at all, use `@MethodSource` only.
23
+
- For `@MethodSource`, name the arguments method `<testMethodName>Arguments` (camelCase, e.g. `testMethodArguments`) and return `Stream<Arguments>` using `Stream.of(...)` and `arguments(...)` with static import.
21
24
- Ensure parameterized test names are human-readable (i.e. no hashcodes); instead add a description string as the first `Arguments.arguments(...)` value or index the test case
22
25
- When converting tuples, create a light dedicated structure instead to keep the typing system
23
26
- Instead of checking a state and throwing an exception, use JUnit asserts
@@ -27,3 +30,35 @@ When converting Groovy code to Java code, make sure that:
27
30
- Do not mark local variables `final`
28
31
- Ensure variables are human-readable; avoid single-letter names and pre-define variables that are referenced multiple times
29
32
- When translating Spock `Mock(...)` usage, use `libs.bundles.mockito` instead of writing manual recording/stub implementations
33
+
34
+
TableTest usage
35
+
Dependency, if missing add:
36
+
- Groovy: testImplementation libs.tabletest
37
+
- Kotlin: testImplementation(libs.tabletest)
38
+
39
+
Import: `import org.tabletest.junit.TableTest;`
40
+
41
+
JDK 8 rules:
42
+
- No text blocks.
43
+
- @TableTest must use String[] annotation array syntax:
44
+
```
45
+
@TableTest({
46
+
"a | b",
47
+
"1 | 2"
48
+
})
49
+
```
50
+
51
+
Spock `where:` → @TableTest:
52
+
- First row = header (column names = method parameters).
53
+
- Add `scenario` column as first column (display name, not a method parameter).
54
+
- Use `|` delimiter; align columns so pipes line up vertically.
55
+
- Prefer single quotes for strings with special chars (e.g., `'a|b'`, `'[]'`).
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.
0 commit comments