Sobes.tech
Middle+

What will you do if there are no tests in the project and the customer does not want to spend time and money on their development?

sobes.tech AI

Answer from AI

I would take the following steps:

  • Discuss with the client the risks of not having tests (increased error rate, support and development difficulties, potential financial losses due to failures).
  • Suggest starting with the most critical parts of the project where errors would be most costly.
  • Show examples of how test automation can speed up development in the future, reducing costs for bug fixes.
  • Begin implementing unit tests for new code or during refactoring of existing parts. This is less costly and gradually demonstrates the benefits of testing.
  • Propose implementing basic integration tests for key interactions within the system.
  • Set up CI/CD for automatic test execution upon changes.
  • Keep track of found bugs and demonstrate how they could have been prevented with tests.
  • Look for opportunities to introduce automated tests based on analysis of existing code and its frequently used parts during other work (e.g., optimization or enhancement of functionality).

Example of implementing a test for a frequently breaking function:

# Original function without tests
def calculate_discount(price, discount_percentage):
    if discount_percentage > 100 or discount_percentage < 0:
        raise ValueError("Discount percentage invalid")
    discount = price * (discount_percentage / 100)
    return price - discount

# Adding a simple unit test
import unittest

class TestDiscountCalculation(unittest.TestCase):

    def test_valid_discount(self):
        # Test for correct case
        self.assertAlmostEqual(calculate_discount(100, 10), 90.0)

    def test_zero_discount(self):
        # Test for zero discount
        self.assertAlmostEqual(calculate_discount(100, 0), 100.0)

    def test_full_discount(self):
        # Test for 100% discount
        self.assertAlmostEqual(calculate_discount(100, 100), 0.0)

    def test_invalid_discount_negative(self):
        # Test for negative discount (expecting exception)
        with self.assertRaises(ValueError):
            calculate_discount(100, -10)

    def test_invalid_discount_too_high(self):
        # Test for discount above 100% (expecting exception)
        with self.assertRaises(ValueError):
            calculate_discount(100, 110)

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

Thus, I would gradually introduce testing, demonstrating its value to the client in practice, even if initially they are reluctant to invest.

What will you do if there are no tests in the project… - sobes.tech