Junior — Middle
Do you create unit tests for code written by colleagues?
sobes.tech AI
Answer from AI
Yes, writing unit tests for colleagues' code is an important practice to ensure the quality and stability of the project. Unit tests help identify errors early and document the expected behavior of functions.
Here's a simple example of a unit test in Python using the unittest module:
import unittest
from my_module import add
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 helps keep the code functional when making changes.