Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Introduce mechanism of lightweight model schema verification for qml unit tests #16364

Open
micieslak opened this issue Sep 19, 2024 · 0 comments
Assignees

Comments

@micieslak
Copy link
Member

micieslak commented Sep 19, 2024

Description

Motivation
Good unit tests are independent and isolated. When tested component requires some input data, like model, that data should be mocked, not produced by other real components (like e.g. adaptors) directly in the test. Doing that would introduce inter-dependency and make test not fully "unit" test. On the other hand relaying always on synthetic data makes us unsure whether components are compatible with each other. This ticket describes proposal of solution of that problem.

The idea is to define simple way of describing model structure, e.g. using json-like js object and keep those definitions next to unit tests (but not directly in unit-test files as they are intended to be accessed from multiple tests):

    readonly property var schema: [
        {
            role: "key",
            type: "string"
        },
        {
            role: "symbol",
            type: "string"
        },
        {
            role: "icon",
            type: "url"
        },
        {
            role: "balances",
            type: "model",
            schema: [
                {
                    role: "balance",
                    type: "text"
                }
            ]
        }
    ]

It would create the ability to define such model descriptions for components both consuming and providing models, like adaptors or views.

Once defined the schema can be used in following way to assure consistency and interoperability of components regarding exchanged data:

  • test model data used in component's unit test should be checked if match the defined schema
  • unit test should verify if component (adaptors) output model matches the defined schema
  • separate unit test should verify if schema of two components used together in the application match each-other

The checks could be done by dedicated testing utility, e.g.

// checks if given model is compliant with schema
ModelSchemaVerification.verifyModel(model, schema)

// checks if two schemas are compatible (e.g. adaptor's output and view's input)
ModelSchemaVerification.checkSchemasCompatibility(schemaA, schemaB)

This approach could give ability of testing component's interoperability on model data level, but with good isolation within particular unit-tests.

The diagram depicting the flow can be found here: https://miro.com/app/board/uXjVLdeD6fs=/

@micieslak micieslak self-assigned this Sep 19, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
Status: No status
Development

No branches or pull requests

1 participant