Skip to main content

Sorts unit tests

This section provides a comprehensive overview of the unit testing procedures implemented for Sorts. It highlights the significance of unit testing in ensuring reliability and functionality of individual components within the codebase.

We exclusively employ unit testing to validate the behavior and functionality of each isolated unit of code. These tests meticulously scrutinize the logic and functionality of components such as sorting algorithms and intricate edge cases,

Our unit test are seamlessly integrated into our CI/CD pipeline, running automatically every time a developer pushes changes to our repository. They also can be executed locally. To run unit tests in Sorts locally, navigate to the universe repository and execute the following command:

m . /sorts/test

To develop a unit test, add it to the sorts/test folder and include the following configuration:

def test_check_url_components() -> None:
#Test implementation goes here

When writing unit tests, adhere to these steps to ensure that the tests are repeatable, fast, independent, and descriptive:

  • Test file: We store our tests using the same structure as our repository. Inside universe/sorts/test/ you can find our unit tests. Look for the test_module_to_test.py file or add it if missing.

  • Write the test: Begin writing the test once the file is ready. Consider the purpose of the function, method, or class being tested, and anticipate its behavior with different inputs. Identify extreme scenarios to include in the test cases, which are crucial for weiting comprehensive assertions.

    With this setup, yo can run the test using the following command:

    m . /sorts/test
  • Assertions: Validate the expected behaviour using assertions. Verify results, the number of function, etc.

After preparing ypur test, format your code by executing the following command within the universe repository:

m . /formatPython/default

Ensure code quality by utilizing a linter:

m . /lintPython/imports/sorts