Top Banner
Budapest, 26-28 October 2016 CONTRACT TESTING IN THE CLOUD IN GEHC Presented by Andras Naszrai © All rights reserved
19

CONTRACT TESTING IN THE CLOUD IN GEHC...Testing Gherkin (JBehave) Mock/Stub (WireMock) • Data Driven Testing • only the data is needed from the user, everything else is there •

Apr 19, 2021

Download

Documents

dariahiddleston
Welcome message from author
This document is posted to help you gain knowledge. Please leave a comment to let me know what you think about it! Share it to your friends and learn new things together.
Transcript
Page 1: CONTRACT TESTING IN THE CLOUD IN GEHC...Testing Gherkin (JBehave) Mock/Stub (WireMock) • Data Driven Testing • only the data is needed from the user, everything else is there •

Budapest, 26-28 October 2016

CONTRACT TESTING IN THE CLOUD IN GEHCPresented by Andras Naszrai 

© All rights reserved

Page 2: CONTRACT TESTING IN THE CLOUD IN GEHC...Testing Gherkin (JBehave) Mock/Stub (WireMock) • Data Driven Testing • only the data is needed from the user, everything else is there •

ABOUT CONTRACTSWhat is a contract? Why do we test it?

© All rights reserved

Page 3: CONTRACT TESTING IN THE CLOUD IN GEHC...Testing Gherkin (JBehave) Mock/Stub (WireMock) • Data Driven Testing • only the data is needed from the user, everything else is there •

Microservice Architecture

3

• The system is decomposed into small components with narrow scope

• Communication between the components is done over the network

• The individual components have their own independentlifecycle and they are independent deployment units

©All rights reserved

Page 4: CONTRACT TESTING IN THE CLOUD IN GEHC...Testing Gherkin (JBehave) Mock/Stub (WireMock) • Data Driven Testing • only the data is needed from the user, everything else is there •

Relationships in Microservice Architecture

4

• Are asymmetric, they follow the server‐client model• Server is called provider, as it provides a service and the client 

is called consumer for similar reasons• Usually they use HTTP (RESTful)• Or some kind of messaging protocol, like AMQP

©All rights reserved

Page 5: CONTRACT TESTING IN THE CLOUD IN GEHC...Testing Gherkin (JBehave) Mock/Stub (WireMock) • Data Driven Testing • only the data is needed from the user, everything else is there •

Contract

5

• A contract is formed when a component becomes the consumer of another

• It describes how the service is consumed by the consumer

• It contains the consumer’s expectations about• Input‐output data structures• Performance• Concurrency characteristics

©All rights reserved

Provider

Consumer

{"id": "1","firstName": "Tom", "lastName": "Cruise"

}

Page 6: CONTRACT TESTING IN THE CLOUD IN GEHC...Testing Gherkin (JBehave) Mock/Stub (WireMock) • Data Driven Testing • only the data is needed from the user, everything else is there •

Contract Testing

6

• Contract testing aims to ensure that a consumer’s dependency on a provider is continuously fulfilled

• Therefore• It is done on the provider• from the consumer’s point of view• Focus is on the behaviour on the 

interface (not on the domain logic)

© All rights reserved

Provider

Consumer

{"id": "1","firstName": "Tom", "lastName": "Cruise"

}

Page 7: CONTRACT TESTING IN THE CLOUD IN GEHC...Testing Gherkin (JBehave) Mock/Stub (WireMock) • Data Driven Testing • only the data is needed from the user, everything else is there •

CONCEPTS USEDThe building blocks

© All rights reserved

Page 8: CONTRACT TESTING IN THE CLOUD IN GEHC...Testing Gherkin (JBehave) Mock/Stub (WireMock) • Data Driven Testing • only the data is needed from the user, everything else is there •

Concepts used

8 © All rights reserved

Data Driven Testing

Gherkin (JBehave)

Mock/Stub (WireMock)

• Data Driven Testing• only the data is needed from the user, everything else is there

• Gherkin (JBehave)• Self‐documenting• Automatic translation of data into 

test

• Mock/Stub (WireMock)• Helps the isolation of the tested 

microservice

Page 9: CONTRACT TESTING IN THE CLOUD IN GEHC...Testing Gherkin (JBehave) Mock/Stub (WireMock) • Data Driven Testing • only the data is needed from the user, everything else is there •

Cloud services

9 © All rights reserved

Page 10: CONTRACT TESTING IN THE CLOUD IN GEHC...Testing Gherkin (JBehave) Mock/Stub (WireMock) • Data Driven Testing • only the data is needed from the user, everything else is there •

Testing as a Software as a Service

• MyApplication• Is a data driven test tool• Sitting in the cloud• Listening on HTTP for test execution requests

10 © All rights reserved

Page 11: CONTRACT TESTING IN THE CLOUD IN GEHC...Testing Gherkin (JBehave) Mock/Stub (WireMock) • Data Driven Testing • only the data is needed from the user, everything else is there •

WHAT WE DIDContract Test Executor Service

© All rights reserved

Page 12: CONTRACT TESTING IN THE CLOUD IN GEHC...Testing Gherkin (JBehave) Mock/Stub (WireMock) • Data Driven Testing • only the data is needed from the user, everything else is there •

We defined our MVP

12

• Support HTTP contracts • 100% data driven• Software as a Service• Support Oauth 2.0• Automatic mocking for HTTP based dependencies• Load binary/JSON data from file

©All rights reserved

Page 13: CONTRACT TESTING IN THE CLOUD IN GEHC...Testing Gherkin (JBehave) Mock/Stub (WireMock) • Data Driven Testing • only the data is needed from the user, everything else is there •

First we needed a data format

13 © All rights reserved

1. Credentials2. DataRecords

• Operation• HTTP method• Parameters• Response

Page 14: CONTRACT TESTING IN THE CLOUD IN GEHC...Testing Gherkin (JBehave) Mock/Stub (WireMock) • Data Driven Testing • only the data is needed from the user, everything else is there •

Then we needed a way to convert data to test

14 © All rights reserved

Page 15: CONTRACT TESTING IN THE CLOUD IN GEHC...Testing Gherkin (JBehave) Mock/Stub (WireMock) • Data Driven Testing • only the data is needed from the user, everything else is there •

And a way to convert data to mock

15 © All rights reserved

Page 16: CONTRACT TESTING IN THE CLOUD IN GEHC...Testing Gherkin (JBehave) Mock/Stub (WireMock) • Data Driven Testing • only the data is needed from the user, everything else is there •

The rest was just implementation detail

16

We used 3rd party libs for• Oauth 2.0 support• Binary data conversion• JSON data conversion

Relied on• Spring• jackson

©All rights reserved

Page 17: CONTRACT TESTING IN THE CLOUD IN GEHC...Testing Gherkin (JBehave) Mock/Stub (WireMock) • Data Driven Testing • only the data is needed from the user, everything else is there •

The solution

17 © All rights reserved

Cloud

DependencyMock 1

DependencyMock 2

Contract Test Executor

Component

AuthN service

AuthZ service

Deploy dependency mocksand set up communication routes

Authenticate user(Get bearer token)

Deploy the tested component

Start the testAuthorize transactions with bearer token

Communicate with mocks as needed

Initiate the test execution by sending 

all the required resources

Zip test results and return

Page 18: CONTRACT TESTING IN THE CLOUD IN GEHC...Testing Gherkin (JBehave) Mock/Stub (WireMock) • Data Driven Testing • only the data is needed from the user, everything else is there •

Highlights, achievements

• Uses the same data structure for test input and mock data• Isolates the tested component automatically• It is self contained• Hides the implementation details of the test environment completely (you don’t have to write code to do automated testing)

• It is really a service in the cloud, that anyone can access

Page 19: CONTRACT TESTING IN THE CLOUD IN GEHC...Testing Gherkin (JBehave) Mock/Stub (WireMock) • Data Driven Testing • only the data is needed from the user, everything else is there •

19

Thank You for your attention!

©All rights reserved