Junior — Middle
What types of tests do you usually create and what is each of them intended for?
sobes.tech AI
Answer from AI
I usually create the following types of tests:
- Unit tests: check individual methods or classes to ensure they work correctly in isolation.
- Integration tests: verify the interaction between multiple components or layers of the application.
- Functional tests: ensure the system performs business functions according to requirements.
- Regression tests: rerun after changes to ensure that existing functionality has not broken.
Example of a simple unit test in Java using JUnit:
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));
}
}