Sobes.tech
Junior — Middle

Do you practice test-driven development (TDD) in your work?

sobes.tech AI

Answer from AI

Yes, test-driven development (TDD) is useful for improving code quality and preventing errors. In TDD, a test is written first, describing the required behavior, then the minimal code is written to pass the test, and finally, the code is refactored.

This helps to:

  • Clearly define functional requirements
  • Quickly find and fix errors
  • Maintain test coverage

Example in Python using unittest:

import unittest

def add(a, b):
    return a + b

class TestAdd(unittest.TestCase):
    def test_add_positive(self):
        self.assertEqual(add(2, 3), 5)

if __name__ == '__main__':
    unittest.main()

In TDD, a test is written first that initially does not pass, then the add function is implemented so that the test passes.