Senior
Do you write tests? What types of testing do you use?
sobes.tech AI
Answer from AI
Yes, I always write tests. Depending on the task, I use different types of testing:
- Unit tests — check individual methods or classes. They allow for quick detection of errors at the code level.
- Integration tests — verify the interaction between components.
- Functional tests — test the application's operation from the user's perspective.
- Regression tests — ensure that new changes haven't broken existing functionality.
In Java, I usually use JUnit for unit tests and Mockito for mocking dependencies. Here's a simple example of a unit test in JUnit 5:
import org.junit.jupiter.api.Test;
import static org.junit.jupiter.api.Assertions.*;
class CalculatorTest {
@Test
void additionTest() {
Calculator calc = new Calculator();
assertEquals(5, calc.add(2, 3));
}
}
Testing helps improve the reliability and quality of the code.