Recently while searching for some tool for testing web services,I came across Stubby4j ,it is highly flexible and configurable tool for testing interactions of SOA applications with web services (REST, SOAP, WSDL etc.) over HTTP(S) protocol. It is an actual HTTP server (stubby4j uses embedded Jetty) that allows stubbing of external systems with ease for integration, contract & behavior testing.
Stubby4j has following advantages over other tools:
- You can simulate responses from real servers
- Allows invocation of service call for services which are not ready yet or in-accessible due to various reasons.
- Simulates support for different types of HTTP authentication.
- Enables delayed responses for performance and stability testing
- Emulate external webservice in a SANDBOX for your application to consume over HTTP(S)
- HTTP request verification and HTTP response stubbing
- Regex support for dynamic matching on URI, query params, headers, POST payload (ie:. mod_rewrite in Apache)
- Dynamic token replacement in stubbed response, by leveraging regex capturing groups as token values during HTTP request verification
- Record & Replay. The HTTP response is recorded on the first call, having the subsequent calls play back the recorded HTTP response, without actually connecting to the external server
- Dynamic flows. Multiple stubbed responses on the same stubbed URI to test multiple application flows
- Fault injection, where after X good responses on the same URI you get a bad one
- Serve binary files as stubbed response content (images, PDFs. etc.)
- Embed stubby4j to create a web service SANDBOX for your integration test suite
Why would a developer love it ?
- Simulate responses from real server and don’t care (or cannot) to go over the network
- Third party web service your application suppose to contract with is not ready yet
- Verify that your code makes HTTP requests with all the required parameters and/or headers
- Verify that your code correctly handles HTTP error codes
- You want to trigger response from the server based on the request parameters over HTTP or HTTPS
- Support for any of the available HTTP methods
- Simulate support for different types of HTTP Authorizations: Basic, Bearer Token & others
- Support for HTTP 30x redirects
- Provide canned answers in your contract/integration tests
- Enable delayed responses for performance and stability testing
- Avoid to spend time coding for the above requirements
- Concentrate on the task at hand
QA use cases stubby4j?
- Specifiable mock responses to simulate page conditions without real data.
- Ability to test polling mechanisms by stubbing a sequence of responses for the same URI
- Easily swappable data config files to run different data sets and responses.
- All-in-one stub server to handle mock data with less need to upkeep code for test generation
- version >= 4.0.0: Oracle JRE v1.8.0_60
- version >= 3.0.0: Oracle JRE v1.7.0_76
- version = 2.0.22: Oracle JRE v1.7.0_04
- version < 2.0.22: Oracle JRE 1.6.0_65-b14-462
- Download the latest stubby4j version (the JAR archive).
- Create the following local YAML file:
- request: method: GET url: /hello-world response: status: 200 headers: content-type: application/json body: Hello World!
- Execute the downloaded stubby JAR using command
java -jar stubby4j-x.x.xx.jar -d <PATH_TO_YOUR_CREATED_LOCAL_YAML_FILE>
- Navigate to
http://localhost:8882/hello-worldto get the stubbed response “Hello World!”
- Navigate to stubby4j admin portal at
http://localhost:8889/statusto see what has been stubbed & other useful data
Like this post? Don’t forget to share it!