-
Notifications
You must be signed in to change notification settings - Fork 329
Sample usage of @TableTest.
#10814
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
AlexeyKuznetsov-DD
wants to merge
8
commits into
master
Choose a base branch
from
alexeyk/table-test-example
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+184
−77
Open
Sample usage of @TableTest.
#10814
Changes from all commits
Commits
Show all changes
8 commits
Select commit
Hold shift + click to select a range
4d811cb
Sample usage of `@TableTest`.
AlexeyKuznetsov-DD 60ec4bf
feat(json): Improve tests
PerfectSlayer 97e35b9
Merge branch 'master' into alexeyk/table-test-example
AlexeyKuznetsov-DD 264bb80
Merge remote-tracking branch 'origin/bbujon/json-tests' into alexeyk/…
AlexeyKuznetsov-DD 17cfbfd
Apply changes from review
AlexeyKuznetsov-DD eb91581
Minor
AlexeyKuznetsov-DD 13ea2cd
Improved skills
AlexeyKuznetsov-DD e735ccb
Renamed skill
AlexeyKuznetsov-DD File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,79 @@ | ||
| --- | ||
| name: migrate-junit-source-to-tabletest | ||
| description: Convert JUnit 5 @MethodSource/@CsvSource/@ValueSource parameterized tests to @TableTest (JDK8) | ||
| --- | ||
| Goal: Migrate JUnit 5 parameterized tests using @MethodSource/@CsvSource/@ValueSource to @TableTest with minimal churn and passing tests. | ||
|
|
||
| Process (do in this order): | ||
| 1) Locate targets via Grep (no agent subprocess). Search for: "@ParameterizedTest", "@MethodSource", "@CsvSource", "@ValueSource". | ||
| 2) Read all matching files up front (parallel is OK). | ||
| 3) Convert eligible tests to @TableTest. | ||
| 4) Write each modified file once in full using Write (no incremental per-test edits). | ||
| 5) Run module tests once and verify "BUILD SUCCESSFUL". If failed, inspect JUnit XML report. | ||
|
|
||
| Dependency: | ||
| - If missing, add: | ||
| - Groovy: testImplementation libs.tabletest | ||
| - Kotlin: testImplementation(libs.tabletest) | ||
|
|
||
| Import: | ||
| - Ensure: import org.tabletest.junit.TableTest; | ||
|
|
||
| JDK 8 rules: | ||
| - No text blocks. | ||
| - @TableTest must use String[] annotation array syntax: | ||
| @TableTest({ "a | b", "1 | 2" }) | ||
|
|
||
| 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', '[]', '{}', ' '). | ||
|
|
||
| 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 | ||
| - 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 '[]'/'{}'). | ||
|
|
||
| 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. | ||
| - Use `@MethodSource`-only only when tabular representation is not practical for the test. | ||
|
|
||
| Do NOT convert when: | ||
| - Most rows require complex builders/mocks. | ||
| - Parameters are arrays (String[], int[]) — keep @MethodSource (or refactor to List to convert). | ||
|
|
||
| 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 | ||
|
|
||
| Never: | ||
| - --info | ||
| - extra gradle runs just to “confirm” | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.