Skip to content

Tests for annotations #652

Open
Open
@jdesrosiers

Description

@jdesrosiers

I recently published a library for working with annotations and included a set of tests in JSON that could be adopted here if there is interest. These tests are agnostic of any output format. They just test what annotations should appear (or not appear) on which values of an instance.

Here's a example:

{
  "title": "`title` is an annotation",
  "schema": {
    "title": "Foo"
  },
  "subjects": [
    {
      "instance": 42,
      "assertions": [
        {
          "location": "#",
          "keyword": "title",
          "expected": ["Foo"]
        }
      ]
    }
  ]
}

Notes/Comments/Rationale:

  • These tests were technically written for the theoretical stable release, but are effectively compatible with 2020-12. They only include $schema if a test is specifically covering a draft release.
  • I wrote my implementation such that older releases were forward-compatible with annotation behavior. That means that you can get annotations from a draft-07 schema even though annotations weren't defined as a thing yet. Assuming others interpret things the same way, the schemas in these tests can be assumed to be using any draft as long as the draft understands all the necessary keywords in the schema.
  • I don't implement annotations that are for inter-keyword communications and therefore didn't write tests for those.
  • The tests are written from the perspective of what annotations are applied to a specific JSON instance location. That means there's no way to test for where in the schema an annotation came from ($defs, properties, etc). I don't think that should matter. I think blackbox outcome testing is the right level to be testing for this kind of thing.
  • "expected" is an array because there's always a chance that an annotation is applied multiple times to any given instance location. However, the ordering of this array is not important. I wrote the tests such that the most recently encountered value for an annotation during evaluation is first in the array. Generally, when a schema has multiple annotations for the same location, users expect the most recent value to override the previous values. The array is ordered this way so that people who expect the overriding behavior can always just choose the first value, but that ordering is an implementation choice and shouldn't be considered when writing a test harness against these tests.

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementAn enhancement to the tooling or structure of the suite (as opposed to a new test).missing testA request to add a test to the suite that is currently not covered elsewhere.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions