Reputation: 141
I am new to API Testing and do not understand mocking responses from API calls so any help would be appreciated.
I have searched for the information online and nothing much is available, it seems except for the mock-server documentation which I am not able to understand much.
I am trying to use Mock-Server to mock the api responses for Get/Put/Post requests for API Testing while the Devs are working on the api developemnet and I do not know how to store the received response in a variable.
What I need to do is to send a request (Get/Post) and receive a response (Body/Header/StatusCode) in a variable so that I can use it for further use (assertions etc)
Anybody having experience around how to use mock-server and can provide an example would be a good help.
I am using Maven/Java/TestNG
Upvotes: 1
Views: 3094
Reputation: 913
http://www.mock-server.com/ has great documentation.
You can stuff the response code, body, headers, and errors into whatever variable you want (hashset, string, etc.) through URLConnection so long as you want to rebuild the raw response.
But it sounds like you want the raw response, in which case you should see Getting raw HTTP response headers
However, if you want to test APIs, you might want to check out tools like https://www.getpostman.com/
Upvotes: 1