Junior — Middle
Do you use automated tests when writing code?
sobes.tech AI
Answer from AI
Yes, I use automated tests when writing code because they help quickly identify errors and ensure stability when making changes. In Python, frameworks like unittest, pytest, or doctest are often used for this purpose.
Here's a simple example of a test using pytest:
# file test_example.py
def add(a, b):
return a + b
def test_add():
assert add(2, 3) == 5
assert add(-1, 1) == 0
Running the tests with the command pytest will confirm that the function works correctly.