Skip to content

Skims unit tests

Unit tests in Skims focus on verifying the functionality of individual units or components of our software.

Our unit test run in our CI/CD pipeline, every time a developer pushes changes to our repository. They also can be run locally. To run locally the unit tests in Skims, enter the universe repository and run:

Terminal window
m . /testPython/skims@unittesting

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

@pytest.mark.skims_test_group("unittesting")
def test_check_url_components() -> None:
#Test implementation goes here

When writing unit tests, you can follow these steps to ensure that the test is repeatable, fast, independent, and descriptive:

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

  • Write the test: Add the skims_test_group decorator to your test function. This decorator categorizes your test under a specific group name, ensuring consistency across all unit tests in Skims. To add this decorator, simply include it in your test function with the desired group name. Then, ensure that the same group name (unittesting) is added to skims/test/test_groups.json. With this setup, yo can run the test using the following command:

    Terminal window
    m . /testPython/skims@group_name
  • Assertions: Test the expected behavior. We use assertions to validate results, the number of function or mock calls, and the arguments used in mocks.

Once your test is ready, format your code by running this command within the universe repository:

Terminal window
m . /formatPython/default

And use a linter:

Terminal window
m . /lintPython/module/skimsTest