Skip to content

Add shared fields and cases alias to @ObjectSource #185

@em3s

Description

@em3s

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 shared and cases parameters to @ObjectSource
  • Update processor: resolve test data from cases.ifBlank { value } (backward compatible)
  • Merge shared fields 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 for value
  • @ObjectSource(shared = "...", cases = "...") merges shared fields into every test case
  • Function parameters are resolved from both shared (shared) and cases (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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementNew feature or request

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions