Middle
How much do you cover your code with tests? How do you write tests?
sobes.tech AI
Answer from AI
I strive to cover code with tests as comprehensively as possible, especially critical and complex parts. I usually write unit tests using the standard modules unittest or pytest.
Approach to writing tests:
- Tests should be isolated and independent.
- I use fixtures and mock objects to simulate external dependencies.
- I check both positive and negative scenarios.
- I write tests in parallel with feature development (TDD, if possible).
Example of a simple test with pytest:
import pytest
def add(a, b):
return a + b
def test_add():
assert add(2, 3) == 5
assert add(-1, 1) == 0