Unit tests
Write unit tests to test pipeline code.
Create unit tests and run tests in CI/CD pipeline
You can create a tests
folder in your project folder and put unit tests in this folder.
In your CI/CD pipeline, you can cd
into the project’s folder and run the following command
to run unit tests.
Example unit tests
End-to-end test for a pipeline:
Test environment
When running unit tests, the env
variable’s value in the method’s kwargs
is test
.
You can leverage this variable to change the code logic or config used in the unit tests.
Mocking IO libraries
When writing unit tests, you may need to mock the IO libraries to verify that the pipeline is being executed properly without actually calling the database or warehouse directly.
If you are using the provided Mage IO libraries, you can mock the libraries in the following way:
In the above example, we are mocking the BigQuery
IO class in the data loader, and the
Postgres
IO class in the data exporter.
Was this page helpful?