Skip to main content

Tests object schema

Tests are assertions you make about your models and other resources in your dbt project. When you run dbt test, dbt will tell you if each test in your project passes or fails. You can query tests through the Discovery API to understand information about them.

The Example query illustrates a few fields you can query with the tests object and how to filter by last-known result. Refer to Fields to view the entire schema, which provides all possible fields you can query.

Arguments

When querying for tests, you can use the following arguments:

Fetching data...

Deprecation: lastKnownResult

The single-value filter field lastKnownResult: TestStatus is deprecated. You should now use lastKnownResults: [TestStatus] to filter tests by one or more result statuses. If you pass both fields in the same query, lastKnownResults takes precedence. Refer to Filter tests by last-known result for more information.

Filter tests by last-known result

You can filter tests by one or more last-known result values. Use lastKnownResults with any combination of these TestStatus values:

  • pass
  • fail
  • error
  • skipped
  • warn

You can still use the deprecated lastKnownResult, but If you pass both fields in the same query, lastKnownResults takes precedence.

An empty list [], omitting lastKnownResults, or passing null applies no filter on last-known result. All tests are returned regardless of result status.

Example query

You can return tests whose last-known result is error or fail:

query {
environment(id: 834) {
applied {
tests(
filter: {
lastKnownResults: [error, fail]
},
first: 100
) {
edges {
node {
name
model
description
expect
resourceType
testType
given
lastKnownResult
}
}
}
}
}
}

You can combine lastKnownResults with other filters on TestAppliedFilter, such as testTypes:

query {
environment(id: 834) {
applied {
tests(
filter: {
testTypes: [GENERIC_DATA_TEST, SINGULAR_DATA_TEST],
lastKnownResults: [fail]
},
first: 100
) {
edges {
node {
name
model
description
expect
resourceType
testType
given
lastKnownResult
}
}
}
}
}
}

Fields

When querying for tests, you can use the following fields:

Fetching data...

Key fields from nodes

Fetching data...

Was this page helpful?

This site is protected by reCAPTCHA and the Google Privacy Policy and Terms of Service apply.

0
Loading