Skip to content

Ship an XSD for testng.xml alongside the DTD, and keep the two from drifting #3319

Description

@juherr

Part of #3317. Supersedes #2594, whose schema is worth salvaging even though the branch is not.

Why now rather than in 2021

#2594 added an XSD but never wired it to anything: it shipped as a resource and was consumed only by a Kotlin test. Meanwhile validation itself was dead — XMLParser probed the SAX validation feature under an https identifier no parser recognises, so setValidating(true) was never reached. That is fixed in #3315, and the DTD is now genuinely enforced (warn by default). Only now does the choice of schema language actually change anything for users.

What to salvage

The XSD in #2594 is materially better than the Trang dump in #3240: attributes are typed, enumerations are hoisted into named simpleTypes reusable between suite and test, and the DTD prose is converted into real xsd:documentation. Extract it with gh pr diff 2594 --patch rather than reusing the branch, which is 494 commits behind and conflicts throughout — most of its diff is an unrelated rename of ~120 test resources, which is what actually killed it.

Scope

  • Update the schema: drop junit (removed from master since), add use-global-thread-pool and share-thread-pool-for-data-providers.
  • No targetNamespace. Add XSD file for validation #2594 added one without adding xmlns to any suite file, which makes a namespace-aware validator unable to resolve <suite> — almost certainly why its data provider was red. A namespace is a breaking change for every existing testng.xml and is reserved for a future 2.0 of the schema.
  • Settle the cardinality question left open in review on Add XSD file for validation #2594: listeners / packages / method-selectors / suite-files should not be repeatable, and groups should join the choice so that validation stops depending on element order. That ordering constraint is the one real incompatibility the DTD imposes — it is why testng-all.xml had to be reordered in fix(xml): re-enable DTD validation and stop losing data in toXml() #3315, and it is what would bite users if the default moved to strict.
  • Ship the XSD next to the DTD. The DTD stays authoritative for files carrying a <!DOCTYPE>; the XSD becomes the contract the corpus test validates against and something IDEs can complete from.
  • Add a consistency test: the whole corpus must validate under both schemas. The two have already drifted once — the writer advertised testng-1.0.dtd while the reader always resolved testng-1.1.dtd (fixed in fix(xml): re-enable DTD validation and stop losing data in toXml() #3315).

Done when

  • Every suite file in the corpus validates against both the DTD and the XSD.
  • The serialized output of toXml() validates against the XSD, as it already must against the DTD.
  • Add XSD file for validation #2594 is closed with a pointer here.

Note there is no need to rename or move any test resource for this. That is the mistake to avoid repeating.

Metadata

Metadata

Assignees

No one assigned

    Labels

    architectureInternal architecture / refactoringxmltestng.xml suite file parsing

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions