Junior — Middle
Have you created automated tests for your code?
sobes.tech AI
Answer from AI
Yes, I have created automated tests for my Python code using tools like unittest and pytest.
Automated tests help verify the correctness of functions and classes, preventing regressions when making changes to the code.
Here's a simple example of a test using unittest:
import unittest
def add(a, b):
return a + b
class TestAddFunction(unittest.TestCase):
def test_add_positive_numbers(self):
self.assertEqual(add(2, 3), 5)
def test_add_negative_numbers(self):
self.assertEqual(add(-1, -1), -2)
if __name__ == '__main__':
unittest.main()
This approach allows for automatic test execution and integration into CI/CD processes.