Sobes.tech
Middle+

Have you used TDD and unit tests?

sobes.tech AI

Answer from AI

Yes, I actively use TDD (Test-Driven Development) and unit tests in my practice. TDD helps to first write tests that describe the behavior of the functionality, and then implement the code that satisfies these tests. This improves code quality and makes refactoring easier.

Example of a unit test in Java using JUnit 5:

import static org.junit.jupiter.api.Assertions.*;
import org.junit.jupiter.api.Test;

class CalculatorTest {
    @Test
    void testAdd() {
        Calculator calc = new Calculator();
        assertEquals(5, calc.add(2, 3));
    }
}

class Calculator {
    int add(int a, int b) {
        return a + b;
    }
}

This approach allows for quick error detection and maintaining code stability.