Junior — Middle
Have you used testing in your Spring-based project?
sobes.tech AI
Answer from AI
Yes, testing is an important part of development in Spring-based projects. The following approaches are commonly used:
- Unit tests using JUnit and Mockito to test individual components and services.
- Integration tests with Spring Test, which allow running the Spring context and testing component interactions.
An example of a simple service test using JUnit and Spring Boot:
@SpringBootTest
public class UserServiceTest {
@Autowired
private UserService userService;
@Test
public void testFindUserById() {
User user = userService.findById(1L);
assertNotNull(user);
assertEquals(1L, user.getId());
}
}
This approach helps ensure code quality and application stability.