Options
All
  • Public
  • Public/Protected
  • All
Menu

Interface TestController

Entry point to discover and execute tests. It contains TestController.items which are used to populate the editor UI, and is associated with run profiles to allow for tests to be executed.

Hierarchy

  • TestController

Index

Properties(4)

Readonly id

id: string

The id of the controller passed in tests.createTestController. This must be globally unique.

label

label: string

Human-readable label for the test controller.

Readonly items

A collection of "top-level" TestItem instances, which can in turn have their own children to form the "test tree."

The extension controls when to add tests. For example, extensions should add tests for a file when workspace.onDidOpenTextDocument fires in order for decorations for tests within a file to be visible.

However, the editor may sometimes explicitly request children using the resolveHandler See the documentation on that method for more details.

refreshHandler

refreshHandler: undefined | ((token: CancellationToken) => void | Thenable<void>)

If this method is present, a refresh button will be present in the UI, and this method will be invoked when it's clicked. When called, the extension should scan the workspace for any new, changed, or removed tests.

It's recommended that extensions try to update tests in realtime, using a FileSystemWatcher for example, and use this method as a fallback.

returns

A thenable that resolves when tests have been refreshed.

Methods(6)

createRunProfile

Optional resolveHandler

  • A function provided by the extension that the editor may call to request children of a test item, if the TestItem.canResolveChildren is true. When called, the item should discover children and call TestController.createTestItem as children are discovered.

    Generally the extension manages the lifecycle of test items, but under certain conditions the editor may request the children of a specific item to be loaded. For example, if the user requests to re-run tests after reloading the editor, the editor may need to call this method to resolve the previously-run tests.

    The item in the explorer will automatically be marked as "busy" until the function returns or the returned thenable resolves.

    Parameters

    • item: undefined | TestItem

      An unresolved test item for which children are being requested, or undefined to resolve the controller's initial items.

    Returns void | Thenable<void>

createTestRun

  • Creates a TestRun. This should be called by the TestRunProfile when a request is made to execute tests, and may also be called if a test run is detected externally. Once created, tests that are included in the request will be moved into the queued state.

    All runs created using the same request instance will be grouped together. This is useful if, for example, a single suite of tests is run on multiple platforms.

    Parameters

    • request: TestRunRequest

      Test run request. Only tests inside the include may be modified, and tests in its exclude are ignored.

    • Optional name: string

      The human-readable name of the run. This can be used to disambiguate multiple sets of results in a test run. It is useful if tests are run across multiple platforms, for example.

    • Optional persist: boolean

      Whether the results created by the run should be persisted in the editor. This may be false if the results are coming from a file already saved externally, such as a coverage information file.

    Returns TestRun

    An instance of the TestRun. It will be considered "running" from the moment this method is invoked until TestRun.end is called.

createTestItem

  • createTestItem(id: string, label: string, uri?: Uri): TestItem

invalidateTestResults

  • Marks an item's results as being outdated. This is commonly called when code or configuration changes and previous results should no longer be considered relevant. The same logic used to mark results as outdated may be used to drive continuous test runs.

    If an item is passed to this method, test results for the item and all of its children will be marked as outdated. If no item is passed, then all test owned by the TestController will be marked as outdated.

    Any test runs started before the moment this method is called, including runs which may still be ongoing, will be marked as outdated and deprioritized in the editor's UI.

    Parameters

    Returns void

dispose

  • dispose(): void
  • Unregisters the test controller, disposing of its associated tests and unpersisted results.

    Returns void

Generated by TypeDoc. Maintained by 洛竹