Testing in the 21st Century
Alex Soto
@alexsotob
Who Am I?
Alex Soto
Red Hat Engineer
www.lordofthejars.com
@alexsotob
Questions
Software is
eating the world
SOFTWARE IS
EATING THE WORLD
“With great power, there
must also come—

great responsibility.”

Testing
Not talking about traditional tests
Microservices Core Principles
MyService
Monitoring
Tracing
Discovery
API
Invocation
Resilience
Pipeline
Authentication
Logging Elasticity
Microservices architecture
Old Testing Model
Step Up Rule
Evolution
Martin Fowler
Cindy Sridharan
Testing in Dev
ServiceVirtualization
ServiceVirtualization Capture Mode
Service A External Network Service B
Scripts
Proxy
ServiceVirtualization Simulation Mode
Service A External Network Service B
Scripts
Proxy
hoverctl start
hoverctl mode capture
curl --proxy http://localhost:8500 http://time.jsontest.com
hoverctl mode simulate
curl --proxy http://localhost:8500 http://time.jsontest.com
Start Hoverfly Proxy
Override to use Hoverfly Proxy
Stored data
@Mock EmailService email;
Mockito.when(email.receiveBodyMessagesWithSubject("My Subject”))
.thenReturn("This is My Message")
// Test calls
@ClassRule
public static HoverflyRule hoverflyRule =
HoverflyRule.inSimulationMode(SimulationSource.dsl(
service("api.flight.com")
.get("/api/bookings/1")
.willReturn(success("{"bookingId":"1"}",
"application/json"))
));
// Test calls
Record Method
Verify Method Called
Record Service
Verify Service Called
DEMO
Benefits
of SV &
Hoverfly
• Do not relay on external network
• Yet testing all stack
• Hoverfly multi-language
• Can be used as standalone proxy
• Hoverfly JVM
• Integration with JVM proxy
settings
Yet testing all stack trace
ContractTests
Consumer
request
response Stub Server
expectations
Provider
request
response
Result
Define Consumer Expectations Verify Expectations On Provider
@RunWith(Arquillian.class)
public class CrimesConsumerContractTest {
@StubServer URL pactServer;
@Pact(provider = "crimes", consumer = "villains")
public RequestResponsePact returnListOfCrimes(PactDslWithProvider builder) {
return builder
.uponReceiving("Gru villain to get all Crimes")
.path("/crimes/Gru")
.method("GET")
.willRespondWith()
.status(200)
.body(RESPONSE)
.toPact();
}
@Test
@PactVerification("crimes")
public void should_get_list_of_crimes_by_villain() {
CrimesGateway crimesGateway = new CrimesGateway(webClient, pactServer);
final Single<JsonArray> gruCrimes = crimesGateway.getCrimesByVillainName(“Gru");
}
Stub/proxy Server URL
Defines service
Provides predefined Req/Res
Executes real requests
Consumer side
@RunWith(Arquillian.class)
@Provider("crimes")
@ContractsFolder("~/crimescontract")
public class CrimesContractTest {
@ArquillianResource
Target target;
@Test
public void should_validate_contract() {
assertThat(target).withUrl(getCrimesServer()).satisfiesContract();
}
}
Provider under validation
Location of contracts
Http Client
Asserts All Interactions are
Provider side
DEMO
Benefits
of CDC
& Pact
• Consumer Driven Contracts
• Fail fast, independent deployments
• Pact Foundation
• Pact specification v3
• Integration with Several Languages
• JVM, Ruby, Python, Go, .Net, Swift,
JS
• Pact Broker
• Sharing contracts,API
documentation, Overview of
services
ReleasingTo Production
Production is not sacrosanct anymore
Blue-Green Deployments
Blue/Green Deployment
CI/CD
PRODUCTI
ON
ROUTE
R
USERS
BUIL
DSCM
Blue/Green Deployment
CI/CD
PRODUCTI
ON
ROUTE
R
USERS
BUIL
D
SCM
Blue/Green Deployment
CI/CD
PRODUCTI
ON
ROUTE
R
USERS
SCM
Blue/Green Deployment
CD/CD
PRODUCTI
ON
ROUTE
R
USERS
SCM
Canary Release
Canary Deployment
CI/CD
PRODUCTI
ON
ROUTE
R
USERS
SCM
Canary Deployment
CI/CD
PRODUCTI
ON
ROUTE
R
USERS
SCM
Canary Deployment
CI/CD
PRODUCTI
ON
ROUTE
R
USERS
SCM
Canary Deployment
CI/CD
PRODUCTI
ON
ROUTE
R
USERS
SCM
Canary Deployment
CI/CD
PRODUCTI
ON
ROUTE
R
USERS
SCM
Canary Deployment
CI/CD
PRODUCTI
ON
ROUTE
R
USERS
SCM
Canary Deployment
CI/CD
PRODUCTI
ON
ROUTE
R
USERS
SCM
Dark Launches
Dark Launches
DEVELOPME
NT
QA
STAGIN
G
PRODUCTI
ON
ROUTE
R
USERS
SCM
INTERNAL
USERS
ShadowingTraffic
DEVELOPME
NT
QA
STAGIN
G
PRODUCTI
ON
ROUTE
R
USERS
SCM
Istio
As we move to services
architectures, we push the
complexity to the space
between our services
CHRISTIAN POSTA
“
Istio
• Greek word for “sail”
• Fleet configuration
• Routing and Load-Balancing control
• Observability
• ChaosTesting
• Security Options
HTTP1.1,
HTTP2, gRPC,
TCP w/TLS
HTTP1.1,
HTTP2, gRPC,
TCP w/TLS
HTTP1.1,
HTTP2, gRPC,
TCP w/TLS
Pod
Containe
rJVM
Service A
Envoy Side-car
Pod
Containe
rJVM
Service B
Envoy Side-car
Pod
Containe
rJVM
Service C
Envoy Side-car
Istio Pilot Istio Mixer Istio Auth
istioctl,API, config Quota,Telemetry

Rate Limiting,ACL
CA, SPIFFE
Istio Data Plane
New version was released past Friday
This contains deprecated format
Canary Release
Blocking
Fault Injection
Mirroring
EXERCISE
https://bit.ly/2KN2G0s
SecureYour Steps
Stubbing collaborating services
Service A
Service B v1
Service B v2
Host:”serviceb-shadow”
Service C
Service
Virtualization
X
Synthetic transactions
Service A
Service B v1
Service B v2
Host:”serviceb-shadow”
synthetic:true
rollback
Virtualizing test-cutter’s database
Service A
Service B v1
Service B v2
Host:”serviceb-shadow”
Prod DB
Virtual DB
read
Throwaway
write
Materializing test-cluster’s database
Service A
Service B v1
Service B v2
Host:”serviceb-shadow”
Prod DB
Test DB
CDC
kafka streams
consume CDC
Compare live service traffic
Service B v1’
Service B v2
Host:”serviceb-shadow”
Diffy Proxy
Service B v1’’
Noise Detection
Test
Let’s Wind Down
Testing Evolution
Manual
Tests
After
Code
Automa
tic Test
Test
First
TDD and
BDD
Service
Virtualiza
tion and
CDC
Testing in
Production
Automate Everything
“Change is the essential process of
all of existence.”



—SPOCK
ThankYouVery Much
@alexsotob
asotobue@redhat.com

Testing in the 21st Century (ExpoQA)