Skip to content

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 the standard_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 the fetcher gets the data correctly and verify it with the standard_models. i.e MandelbrotData()
    • test_view.py - test the charting visualization creates the right charts
    • test_model.py - test logic of functions, uses live data to ensure function runs properly

Unit Testsยค

  • Context: Toolbox
    • test_helpers.py - test the helpers statically
  • Category: Technical
    • test_methods.py (mock) - test the methods but mock the classes so that there are no dependencies on classes actually instantiating themselves.
  • Command: mandelbrot_channel
    • test_helpers.py - test the helpers statically
    • test_view.py - test the charting visualization returns the correct objects
    • test_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.

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.