contract testing in the cloud in gehc...testing gherkin (jbehave) mock/stub (wiremock) • data...
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 •](https://reader036.vdocuments.us/reader036/viewer/2022071507/61285a0f30b2d85cb928ee25/html5/thumbnails/1.jpg)
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 •](https://reader036.vdocuments.us/reader036/viewer/2022071507/61285a0f30b2d85cb928ee25/html5/thumbnails/2.jpg)
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 •](https://reader036.vdocuments.us/reader036/viewer/2022071507/61285a0f30b2d85cb928ee25/html5/thumbnails/3.jpg)
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 •](https://reader036.vdocuments.us/reader036/viewer/2022071507/61285a0f30b2d85cb928ee25/html5/thumbnails/4.jpg)
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 •](https://reader036.vdocuments.us/reader036/viewer/2022071507/61285a0f30b2d85cb928ee25/html5/thumbnails/5.jpg)
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 •](https://reader036.vdocuments.us/reader036/viewer/2022071507/61285a0f30b2d85cb928ee25/html5/thumbnails/6.jpg)
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 •](https://reader036.vdocuments.us/reader036/viewer/2022071507/61285a0f30b2d85cb928ee25/html5/thumbnails/7.jpg)
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 •](https://reader036.vdocuments.us/reader036/viewer/2022071507/61285a0f30b2d85cb928ee25/html5/thumbnails/8.jpg)
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 •](https://reader036.vdocuments.us/reader036/viewer/2022071507/61285a0f30b2d85cb928ee25/html5/thumbnails/9.jpg)
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 •](https://reader036.vdocuments.us/reader036/viewer/2022071507/61285a0f30b2d85cb928ee25/html5/thumbnails/10.jpg)
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 •](https://reader036.vdocuments.us/reader036/viewer/2022071507/61285a0f30b2d85cb928ee25/html5/thumbnails/11.jpg)
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 •](https://reader036.vdocuments.us/reader036/viewer/2022071507/61285a0f30b2d85cb928ee25/html5/thumbnails/12.jpg)
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 •](https://reader036.vdocuments.us/reader036/viewer/2022071507/61285a0f30b2d85cb928ee25/html5/thumbnails/13.jpg)
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 •](https://reader036.vdocuments.us/reader036/viewer/2022071507/61285a0f30b2d85cb928ee25/html5/thumbnails/14.jpg)
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 •](https://reader036.vdocuments.us/reader036/viewer/2022071507/61285a0f30b2d85cb928ee25/html5/thumbnails/15.jpg)
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 •](https://reader036.vdocuments.us/reader036/viewer/2022071507/61285a0f30b2d85cb928ee25/html5/thumbnails/16.jpg)
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 •](https://reader036.vdocuments.us/reader036/viewer/2022071507/61285a0f30b2d85cb928ee25/html5/thumbnails/17.jpg)
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 •](https://reader036.vdocuments.us/reader036/viewer/2022071507/61285a0f30b2d85cb928ee25/html5/thumbnails/18.jpg)
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 •](https://reader036.vdocuments.us/reader036/viewer/2022071507/61285a0f30b2d85cb928ee25/html5/thumbnails/19.jpg)
19
Thank You for your attention!
©All rights reserved