Your first test
Testing is a crucial part of any data project. Teams can only move fast with confidence. Testing helps build that confidence. In this guide, you will write your first tests. In this guide, we will continue on from the first model guide and will document and test the
employees_by_shift model we created. While this guide is a quick introduction to testing, for further details see the testing section.
Tests are assertions that run on the data. For example, you may want to assert that values in a column are unique or that those values are between a certain range. Quary allows you to write these assertions in a simple way, and then run them on your data to ensure your models are working as expected.
Before we add a test, let's do a quick detour to understand how Quary's documentation and tests are stored. For your new model
employees_by_shift, open the documentation tab as in Your first model.
If you look carefully, all the metadata is inferred. That is because Quary can automatically infer information from the underlying models. None of that documentation is stored. You can add documentation by clicking the
Add the Schema button, the edit button next to description or the
+ button next to the columns. All these should start adding docs, which are stored in a
schema.yaml file. This is where metadata as well as your tests are stored.
Just like the inferred columns, Quary can also infer tests. These are the tests that you can quickly add by clicking them. You can see that Quary has inferred not null and relationship tests. Just as the documentation; when added the test appear in your
Just like you added an inferred test, you can also add other column test by clicking the Add button. This should open a pop-up where you can add a test. For example, let's add a test to make sure that the
number_of_shifts column is not null.
The Quary test inference (skipper) engine enhances the efficiency of your tests by intelligently determining which tests to run. This is particularly useful for large datasets, such as our
stg_employees model, which may contain over 1 million rows.
Once you are happy with the model, you can deploy it to your database with the
Quary: RUN command palette call. The command palette can be opened by pressing
Ctrl + Shift + P on Windows or
Cmd + Shift + P on Mac. You can then search for
Quary: RUN and press enter.
After it has built and deployed, you can run the tests by clicking the
Run Tests button in the top right corner of the model page.
We now have a test model which we can safely deploy to our database and perform further analysis on with confidence 🚀. Now that you have created your first and tested your first model, it's time to do it for real in your own project.