Help! I need mocks for my integration tests
During this talk, you will see the relevance of using mocks for your integration tests and how the developers can create different scenarios of mocks without knowing about the other microservices. Most developers mock the external interaction using some mock library inside the code, producing a fake sensation that everything works fine in the microservice. What happens if something is wrong with the code that the developers mocked?
You will see a short scene where you have an application with some integration tests using a real microservice and how, with the use of Wiremock, the developers could create different scenarios, like introducing latency in the response, exceptions in specific situations, or different responses depending on the parameters of the request.
Andres Sacco
Únete a las actividades que realizaremos

Summary of «Help! I need mocks for my integration tests»
Problem: When working with microservices, it’s common to need integration tests that simulate interactions between different services. However, relying on real services can lead to reproducibility, latency, and fragility issues in tests.
Solution: Using mocks allows tests to be isolated and control the behavior of external services, enabling the creation of more robust and reliable test scenarios.
Tool: The talk focuses on WireMock, an open-source, language-agnostic tool designed for creating HTTP mocks.
WireMock Features:
- Custom Mock Creation: Define specific HTTP responses for different requests, including status codes, headers, and response bodies.
- Latency Simulation: Simulate delays in responses to evaluate application fault tolerance.
- Multiple Protocol Support: Primarily focused on HTTP but can be extended to support other protocols.
- Graphical Interface: Provides a web interface for creating and managing mocks visually.
- Integration with Testing Frameworks: Can be integrated with various testing frameworks, such as JUnit, for executing integration tests.
Benefits of Using WireMock:
- Test Isolation: Allows tests to run independently without relying on external services.
- Reproducibility: Ensures tests run the same way every time.
- Speed: Reduces test execution time by eliminating the need for real service calls.
- Flexibility: Enables simulation of a wide range of scenarios, including errors and adverse network conditions.
Steps to Use WireMock:
- Installation: Can be installed as a Docker image or as a dependency in a Java project.
- Mock Creation: Define mocks in JSON files, specifying the URL, HTTP method, and expected response.
- Integration with Tests: Configure the testing framework to use WireMock and execute tests.
Conclusions:
- WireMock is a powerful and flexible tool for creating HTTP mocks and performing microservice integration tests.
- Using mocks can improve application Quality and reliability.
- The talk provides a practical guide to getting started with WireMock in Java projects.
Additional Recommendations:
- Separate mocks into different files for better organization.
- Use wildcards to create more generic mocks.
- Consider using WireMock’s graphical interface to simplify mock creation.
- Integrate WireMock with other testing frameworks to create more robust CI/CD pipelines.
In summary, the talk presents a practical and effective solution to the challenge of performing reliable and efficient microservice integration tests.
Únete a las actividades que realizaremos

Resumen de la charla: «Help I Need a Mock for My Integration Tests»
Problema: Al trabajar con microservicios, es común necesitar realizar pruebas de integración que simulen la interacción entre diferentes servicios. Sin embargo, depender de servicios reales puede generar problemas de repetibilidad, latencia y fragilidad en las pruebas.
Solución: El uso de mocks (simuladores) permite aislar las pruebas y controlar el comportamiento de los servicios externos, facilitando la creación de escenarios de prueba más robustos y confiables.
Herramienta: La charla se centra en la herramienta WireMock, una solución open-source y agnóstica a lenguajes de programación, diseñada para crear mocks HTTP.
Características de WireMock:
- Creación de mocks personalizados: Permite definir respuestas HTTP específicas para diferentes solicitudes, incluyendo códigos de estado, encabezados y cuerpos de respuesta.
- Simulación de latencia: Permite simular retrasos en las respuestas para evaluar la tolerancia a fallos de las aplicaciones.
- Soporte para múltiples protocolos: Aunque se enfoca principalmente en HTTP, puede ser extendido para soportar otros protocolos.
- Interfaz gráfica: Ofrece una interfaz web para crear y gestionar mocks de forma visual.
- Integración con frameworks de testing: Se puede integrar con diversos frameworks de testing, como JUnit, para ejecutar pruebas de integración.
Beneficios del uso de WireMock:
- Aislamiento de pruebas: Permite ejecutar pruebas de forma independiente, sin depender de servicios externos.
- Repetibilidad: Garantiza que las pruebas se ejecuten de la misma manera cada vez.
- Velocidad: Reduce el tiempo de ejecución de las pruebas al eliminar la necesidad de realizar llamadas a servicios reales.
- Flexibilidad: Permite simular una amplia variedad de escenarios, incluyendo errores y condiciones de red adversas.
Pasos para utilizar WireMock:
- Instalación: Se puede instalar como una imagen de Docker o como una dependencia en un proyecto Java.
- Creación de mocks: Se definen los mocks en archivos JSON, especificando la URL, el método HTTP y la respuesta esperada.
- Integración con pruebas: Se configura el framework de testing para utilizar WireMock y se ejecutan las pruebas.
Conclusiones:
- WireMock es una herramienta poderosa y flexible para crear mocks HTTP y realizar pruebas de integración de microservicios.
- Al utilizar mocks, se pueden mejorar la calidad y la confiabilidad de las aplicaciones.
- La charla proporciona una guía práctica para comenzar a utilizar WireMock en proyectos Java.
Recomendaciones adicionales:
- Separar los mocks en archivos distintos para mejorar la organización.
- Utilizar wildcards para crear mocks más genéricos.
- Considerar el uso de la interfaz gráfica de WireMock para facilitar la creación de mocks.
- Integrar WireMock con otros frameworks de testing para crear pipelines de CI/CD más robustos.
En resumen, la charla presenta una solución práctica y efectiva para abordar el desafío de realizar pruebas de integración de microservicios de manera confiable y eficiente.

Andres Sacco
⌨ Technical Leader | 📝 Writer | 🎤 Speaker