hoverfly
hoverfly copied to clipboard
feature request - convert hoverfly capture into junit test
Is your feature request related to a problem? Please describe. A clear and concise description of what the problem is. Ex. I'm always frustrated when [...]
I follow a 'contract-first' design approach for APIs. This involves writing a contract (WSDL, swagger etc) first then implementing in a particular technology (e.g. java microservice, pega etc etc)
I have used hoverfly as a proxy to capture requests to an existing API. Capturing requests is great.
I am uplifting an API to use a new technology (i.e. same Contract, new implementation). It would be great if I could
- use hoverfly as a proxy to capture requests to the existing API
- use hoverfly to generate junit tests based on the simulation.json
- replay the junit tests agaisnt the new API (same contract, new implementation)
I currently manually capture requests/responses and manually write junit tests to invoke the new api. It seems like hoverfly has all the moving parts to automate the creation of unit tests for me.
Any suggestions to automate this workflow?
Describe the solution you'd like A clear and concise description of what you want to happen.
Describe alternatives you've considered A clear and concise description of any alternative solutions or features you've considered.
Additional context Add any other context or screenshots about the feature request here.
@felixvolz That's a good idea. We have actually done some work on our cloud platform to generate curl commands from a simulation using this tool: https://github.com/Kong/httpsnippet.
The tool can also generate OkHttp or Unirest client code for Java from a HAR file. Here is a conversion of an example HAR file:
httpsnippet example.json --target java --client okhttp --output ./snippets
The output JAVA snippets look like this:
OkHttpClient client = new OkHttpClient();
MediaType mediaType = MediaType.parse("application/x-www-form-urlencoded");
RequestBody body = RequestBody.create(mediaType, "foo=bar");
Request request = new Request.Builder()
.url("http://mockbin.com/har?foo=bar&foo=baz&baz=abc&key=value")
.post(body)
.addHeader("cookie", "foo=bar; bar=baz")
.addHeader("accept", "application/json")
.addHeader("content-type", "application/x-www-form-urlencoded")
.build();
Response response = client.newCall(request).execute();
It doesn't create a JUnit class though.
Converting journal to HAR is probably easier, and hoverfly should be able to output journal in a HAR format, making it compatible with many HAR adaptors as well.
Interesting! Thx for the comprehensive info!