Sobes.tech
Junior — Middle

What tools or approaches do you plan to use to test the functionality of a new microservice?

sobes.tech AI

Answer from AI

There are several approaches typically used to verify the functionality of a new microservice:

  • Unit tests — test individual components and business logic of the microservice.
  • Integration tests — verify the interaction of the microservice with external systems, databases, and other services.
  • Contract testing — ensures that the microservice's API meets client expectations.
  • Smoke tests — quick checks of core functions after deployment.
  • Monitoring and logging — after launch, it is important to set up metrics collection and logs for prompt issue detection.

In Java, JUnit is often used for testing, Mockito for mocking dependencies, Spring Boot Test for integration tests. For testing REST APIs, tools like Postman or REST-assured are used.

An example of a simple unit test with JUnit 5:

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

class MyServiceTest {
    @Test
    void testBusinessLogic() {
        MyService service = new MyService();
        int result = service.calculate(2, 3);
        assertEquals(5, result);
    }
}