-
Notifications
You must be signed in to change notification settings - Fork 13
Add shared fields and cases alias to @ObjectSource #185
Copy link
Copy link
Closed
Labels
enhancementNew feature or requestNew feature or request
Description
Background
@ObjectSource currently has a single value parameter. When test cases share common data (setup payload, base URI, shared config), it must be duplicated per case or handled outside YAML via @BeforeAll — breaking the "YAML alone tells the full story" principle.
Task
- Add
sharedandcasesparameters to@ObjectSource - Update processor: resolve test data from
cases.ifBlank { value }(backward compatible) - Merge
sharedfields into every test case before parameter injection - Add tests for the new functionality
- Update
testing-guide.md
Done When
@ObjectSource("...")continues to work (backward compatible)@ObjectSource(cases = "...")works as alias forvalue@ObjectSource(shared = "...", cases = "...")mergessharedfields into every test case- Function parameters are resolved from both
shared(shared) andcases(per-case)
Notes
Annotation change:
// Before
annotation class ObjectSource(val value: String)
// After
annotation class ObjectSource(
val value: String = "",
val cases: String = "", // alias for value, use when shared is present
val shared: String = "", // shared fields merged into every test case
)Processor logic: val testData = annotation.cases.ifBlank { annotation.value }
Usage:
// Existing — unchanged, backward compatible
@ObjectSource("""
- name: db-basic
create: |
{"database": "db-basic", "comment": "test"}
expected: |
{"database": "db-basic", "comment": "test", "active": true}
""")
fun `create database`(name: String, create: String, expected: String)
// New — shared fields via shared, per-case fields via cases
@ObjectSource(
shared = """
setup: |
{"database": "test-db", "comment": "test"}
""",
cases = """
- name: v3-alias-basic
update: |
{"comment": "updated"}
expected: |
{"alias": "v3-alias-basic", "comment": "updated", "active": true}
- name: v3-alias-empty
update: |
{"comment": "updated empty"}
expected: |
{"alias": "v3-alias-empty", "comment": "updated empty", "active": true}
""",
)
fun `update alias`(
setup: String, // from shared — shared across all cases
name: String, // from cases — per case
update: String, // from cases — per case
expected: String, // from cases — per case
)Both value and cases work for test case data. cases is the preferred name when shared is also present for readability.
Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
enhancementNew feature or requestNew feature or request