Junior — Middle
What tools and libraries for automated testing have you used in your projects?
sobes.tech AI
Answer from AI
In Java projects, I used the following tools and libraries for automated testing:
- JUnit — for writing unit tests, verifying the logic of classes and methods.
- Mockito — for creating mock objects and isolating tested components.
- Selenium WebDriver — for automating web interface testing.
- TestNG — as an alternative to JUnit with extended test management capabilities.
- AssertJ — for convenient and readable assertions in tests.
Example of a simple test with JUnit and Mockito:
import org.junit.jupiter.api.Test;
import static org.mockito.Mockito.*;
import static org.junit.jupiter.api.Assertions.*;
class UserServiceTest {
@Test
void testGetUserName() {
UserRepository repo = mock(UserRepository.class);
when(repo.findNameById(1)).thenReturn("Ivan");
UserService service = new UserService(repo);
String name = service.getUserName(1);
assertEquals("Ivan", name);
}
}