Maximizing Efficiency and Profitability with OnePlan’s Professional Service A...
SpectoLabs Xebia TestWorks Conf October 2016
1. Automated Testing in
a World of Interdependence:
Service Virtualisation for the Modern Age
TestWorksConf Workshop, 7th October
Benji Hooper, Daniel Bryant, John Davenport, Tom Cunliffe
2. About Specto Workshops
• This slide deck is an excerpt from a workshop delivered as part of the
test automation TestWorksConf
• http://testworksconf.com/talk/automated-testing-in-a-world-of-interdependence
• The Specto team run public and private workshops (contact@specto.io)
• All aspects of test automation
• Microservice testing and service virtualisation with Hoverfly
• Incorporating FR / NFR testing into a build pipeline
4. Knight Capital, 2012
$440m loss
Neiman Marcus, Black Friday 2015
IPO cancelled
Stock trading disruption
12 hour outage
Royal Bank of Scotland, 2012
Transactions disrupted worldwide
£500m in fines and
compensation
23. credit to @mogronalol 23
Webserver / Facade Mode
Consumer Producer
Service
Virtualisation
Tool
24. credit to @mogronalol 24
Not Mocking
Service Under Test
Mocking
Dependant Service
Http
Virtual Service
Mocks bleed into the
architectural boundary of
your application
26. credit to @mogronalol 26
Record and replay
Consumer
External
Producer
Service
Virtualisati
on Tool
27. credit to @mogronalol 27
JUnit Example
@Rule
public HoverflyRule hoverflyRule = HoverflyRule.inCaptureMode(“src/test/
resources/external.json").build();
@Test
public void shouldBeAbleToRetrieveABooking() throws URISyntaxException {
// Given
final int bookingId = 1;
// When
final Booking booking = bookingServiceGateway.getBooking(bookingId);
// Then
assertThat(booking.getCustomer()).isEqualTo(“Andrew Morgan”);
assertThat(booking.getDate()).isEqualTo(LocalDate.of(2016,3,1));
}
29. credit to @mogronalol 29
JUnit Example
@Test
public void shouldBeAbleToRetrieveABooking() throws URISyntaxException {
// Given
final int bookingId = 1;
// When
final Booking booking = bookingServiceGateway.getBooking(bookingId);
// Then
assertThat(booking.getCustomer()).isEqualTo(“Andrew Morgan”);
assertThat(booking.getDate()).isEqualTo(LocalDate.of(2016,3,1));
}
@Rule
public HoverflyRule hoverflyRule =
HoverflyRule.buildFromClassPathResource(“external.json").build();
31. credit to @mogronalol 31
Deployment and Infrastructure
Consumer
External
Producer
Virtual
Service
Internal
Producer
Internal
Producer
Internal
Producer
Virtual
Service
Virtual
Service
Virtual
Service
33. Hands-on session
• Exercise 1: Explore an application that needs testing
and create the simulations required to test it
independently
• Exercise 2: Test the circuit breakers in an application
using Hoverfly
• Code available:
• https://github.com/benjih/oreilly-docker-java-shopping
• Edze, Tom, Daniel, Benji and John will be around for
help if needed (and feel free to work with others!)
35. If you create simulations of components…
… then individual components can be
tested in isolation.
36. A simulation of a component behaves
like the real thing…
… it misbehaves like the real thing…
So you can create a realistic, repeatable
test environment…
… and automate all the things.