Adding a Test
๐งช Adding a Testยค
Test Requirementsยค
It is required to add tests to cover all the code that you add to the package. Here are the guidelines to help you organize the tests you need to add.
Overviewยค
Tests are categorized into two main types: 1. Unit Tests: - These test individual units of functionality. - They should be independent from other tests and external dependencies. 2. Integration Tests: - These test the combination of units working together. - They verify full functionality and interaction between components.
Test Organizationยค
The tests should be organized according to the CCCC framework: Core, Context, Category, Command. The directory structure for tests should reflect this organization.
Directory Structureยค
tests/
โโโ integration/
โ โโโ context/
โ โ โโโ category/
โ โ โ โโโ command/
โ โ โ โ โโโ test_queryParams_data_fetcher.py
โ โ โ โ โโโ test_view.py
โ โ โ โ โโโ test_model.py
โ โ โโโ test_methods.py
โ โโโ test_queryParams.py
โโโ unittests/
โโโ context/
โ โโโ category/
โ โ โโโ command/
โ โ โ โโโ test_helpers.py
โ โ โ โโโ test_view.py
โ โ โ โโโ test_model.py
โ โ โโโ test_methods.py
โโโ test_helpers.py
๐ Detailed List of All Testsยค
Integration Testsยค
- Context: Toolbox
test_queryParams.py
- test thestandard_models
- Category: Technical
test_methods.py
- test the methods in the class, and ensure they pass the parameters and instantiate the class correctly
- Command: mandelbrot_channel
test_queryParams_data_fetcher.py
- test thefetcher
gets the data correctly and verify it with the standard_models. i.eMandelbrotData()
test_view.py
- test the charting visualization creates the right chartstest_model.py
- test logic of functions, uses live data to ensure function runs properly
Unit Testsยค
- Context: Toolbox
test_helpers.py
- test thehelpers
statically
- Category: Technical
test_methods.py
(mock) - test themethods
but mock the classes so that there are no dependencies on classes actually instantiating themselves.
- Command: mandelbrot_channel
test_helpers.py
- test thehelpers
staticallytest_view.py
- test the charting visualization returns the correct objectstest_model.py
- test the logic of functions and input validation
!!! tip Use __init__.py
files to group tests together.
You should use __init__.py
files to group tests together and provide the correct namespace for pytest
to find each of the tests, because I have chosen a design pattern to name multiple tests with the same name, and they are just nested in their respective directory.
!!! example Check /tests
for examples
Take a look at tests that have already been created to get a sense of how to test your classes and functions.
!!! warning When you update Polars version, you need to update the humblobject
pickle files as serialization is not always backwards compatible.
Expectations for Test Creationยค
- Independence: Ensure unit tests do not rely on external systems or other tests.
- Comprehensiveness: Write tests to cover all possible edge cases.
- Clarity: Name tests clearly to indicate what functionality they cover.
- Consistency: Follow the CCCC framework for organizing tests.
- Documentation: Document any non-trivial logic within the tests for future reference.