Test Automation

../_images/test_automation.png

Exercise 1: Automated Tests

In test_words.py you find an examples of:

  • a simple test with pytest

  • a test against an Exception

  • a test with a fixture

  • a parametrized test

Run the tests with

uv run pytest

Make the tests work by implementing a word_count() function.

Exercise 2: Roman Numerals

Write a test for a function that convert Roman numerals (e.g. XVI) to arabic numbers.

Then implement the minimal code to make the test pass.

Iterate a few times.

Exercise 3: Tests for the Space Game

Run the tests for the space game with the following command:

uv run pytest -v -x -s --cov

Explain the options.

Exercise 4: Mocking

Also compare the code in mock_example.py Discuss what a context manager is.

../_images/test_problems.png