Merged
Conversation
18fefde to
999ce3a
Compare
Introduces `@TableSource`, a second YAML-based data source for
`@ObjectSourceParameterizedTest`. It accepts a `columns` header and `rows`
list so a dense primitive matrix keeps CSV-like density while staying pure
YAML and using the same name-based parameter binding as `@ObjectSource`.
Intended use:
- `@ObjectSource` — nested / heterogeneous / single-case data
- `@TableSource` — dense primitive matrices where repeating per-case keys
would hurt readability
Example:
@ObjectSourceParameterizedTest
@TableSource("""
columns: [from, event, expected]
rows:
- [IDLE, START, RUNNING]
- [RUNNING, STOP, IDLE]
""")
fun `transition moves state`(from: State, event: Event, expected: State)
Implementation:
- `ObjectSourceExtension` now dispatches on whichever annotation is present
and reuses the same invocation context and parameter resolver. Only one
of the two annotations may appear on a method.
- `TESTING.md` gets a short "Dense matrices" subsection so the decision
between the two annotations is documented in one place.
- `TableSourceTest` covers columns/rows expansion, null handling (`~`),
enum binding, and `@Nested` classes.
This PR is purely additive — no rename, no existing class moved. A later
rename of `ObjectSourceExtension` to something more neutral can land as a
separate, blame-preserving PR from the original author.
999ce3a to
7ab8500
Compare
Covers the error paths introduced by the parser so future changes do not regress them silently: - Blank `value` - Missing `columns` / `rows` keys - Row size does not match columns size - Non-string entries in `columns` - Non-list entries in `rows` - Empty rows list (produces zero test cases) Exposes `parseTableSource` on `ObjectSourceExtension` as a public helper so tests can drive it directly; the test-fixtures source set is a separate Kotlin module from the regular test source set, so `internal` is not sufficient here.
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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
Summary
Adds
@TableSource, a second YAML-based data source for@ObjectSourceParameterizedTest. It accepts acolumnsheader androwslist so dense primitive matrices keep CSV-like density while staying pure YAML and sharing the same name-based parameter binding as@ObjectSource.Why not just keep
@CsvSource?@CsvSourceis a fine tool and for a single file often looks slightly more concise than@TableSource. The reason we are introducing@TableSourceis not density — it is type-processing consistency.Every data-driven test in the project should flow through the same pipeline:
ObjectMappers.YAML, Jackson) for all parameterized data.~), one boolean convention, one nested-object story.@CsvSourceuses a separate conversion pipeline (JUnit'sArgumentConverter), which silently pushes string→domain conversion into test bodies. Today in this repo that shows up as ad-hoc helpers liketoBooleanFlexible(),toStateValue(),handleSpecialValue(),toEventType(),toEventSequence()inside state transition tests — every file re-implements the same CSV-string-to-domain-type coercion. With@TableSource(and a Jackson module registered for the domain types) those helpers become unnecessary: YAML values are already typed when the test body runs.The density argument alone does not justify a new annotation. The unified type pipeline does: one change in one module picks up custom types for every data-driven test, and test bodies stop repeating string-parsing adapters.
Shape comparison, for reference:
Changes
TableSourceannotation (core/src/testFixtures/.../params/TableSource.kt).ObjectSourceExtensionnow dispatches on whichever annotation is present; existing@ObjectSourcebehavior is unchanged.TESTING.mdgets a short "Dense matrices" subsection explaining the split.TableSourceTestcovers columns/rows expansion,~→ null, enum binding, and@Nestedclasses.This PR is purely additive — no rename, no existing class moved. If we want to rename
ObjectSourceExtensionto something more neutral now that it handles both sources, that can land as a separate rename-only PR (100% similarity, blame survives squash merge).Test plan
./gradlew :core:test --tests '*TableSourceTest' --tests '*ObjectSourceTest'green./gradlew :core:testfull suite greenOut of scope
@CsvSource/@MethodSourcetests (tracked in Migrate 33 Kotlin data-driven tests to@ObjectSource#271). Adopting@TableSourceis what unlocks removing the string-parsing helpers in state transition tests.State,StateValue,EventType, ...). That will happen alongside the first migration PR that needs it — there is no need to over-engineer upfront.ObjectSourceExtensionto a neutral name. Separate PR from the original author.@ObjectSource/@TableSourceare both Kotlin-only today; extending to Java requires enabling-parametersproject-wide and a Java-reflection fallback.