Upgrade to Pro — share decks privately, control downloads, hide ads and more …

Consumer Driven Contract Testing con Spring Cl...

Consumer Driven Contract Testing con Spring Cloud Contract

Eddú Meléndez Gonzales

July 06, 2019

Transcript

17 slides
  1. Sobre mí • • Desarrollador Java • Ingeniero de Software

    • Arquitecto por Accidente • Contribuidor Open Source (spring-*, spring-cloud-contract, mybatis, arquillian) • Twitter: @eddumelendez • Blogger: https://blog.eddumelendez.me
  2. Qué necesitamos resolver? • Deployment • APIs • Contracts •

    Testing • Service Discovery • Health Checking • Configuration • Circuit Breaking • Tracing • Logging • Monitoring • ...
  3. Qué necesitamos resolver? • Deployment • APIs • Contracts •

    Testing • Service Discovery • Health Checking • Configuration • Circuit Breaking • Tracing • Logging • Monitoring • ...
  4. Test usando MockRestServiceServer @RestClientTest public class MockServerTest { @Autowired private

    MockRestServiceServer server; @Test public void shouldReturnAllItems() { this.server.expect(requestTo(...uri...)) .andResponse(withSuccess(...body..., ...media type...)); }
  5. Test usando Wiremock @AutoconfigureWireMock public class WireMockTest { @Test public

    void shouldReturnAllItems() { stubFor( get(urlEqualTo(...uri...)) .willReturn( aResponse() .withHeader(...key..., ...value...) .withBody(...body...))); }
  6. Beneficios de Spring Cloud Contract Por lado del Productor: •

    Ofrece DSL para definir contratos • Genera stubs • Genera tests a partir de la definición de contratos
  7. Beneficios de Spring Cloud Contract Por lado del Consumidor: •

    Validación contra los contratos • Ejecución de tests contra stubs generados por el Productor gracias a StubRunner
  8. Features • Soporta mensajería (Integration, Stream, RabbitMQ, Kafka, Camel) •

    Integración con MockMvc • Integración con WebTestClient • Integración con RestDocs • Soporte para Maven y Gradle • Provee StubRunner • Provee reglas en JUnit 4 y extensiones en JUnit Jupiter • Soporta Pact • Definición de contratos a través de YAML

More Decks by Eddú Meléndez Gonzales

Other Decks in Programming