What is the difference between then() and when() in REST Assured?

Prepare for the REST Assured QA Test with multiple choice questions. Enhance your skills with hints and explanations for each question. Get exam-ready today!

Multiple Choice

What is the difference between then() and when() in REST Assured?

Explanation:
The distinction between when() and then() in REST Assured lies in their specific roles within the framework's fluent interface for testing HTTP APIs. When you use when(), you are preparing to perform an action, such as sending a request to the server. This method is where you specify the HTTP method (GET, POST, PUT, DELETE, etc.) and the endpoint you want to interact with. It's essentially about setting up the context of your test and making the API call. Conversely, then() is used to assert the results of the action that was defined by when(). After the API call has been made, then() allows you to specify various assertions to verify the response against expected outcomes. This might include checking the status code, validating the response body, or ensuring that certain headers are present. Therefore, the correct answer effectively describes how when() focuses on the action of sending a request, whereas then() is concerned with verifying and asserting the outcomes of that request.

The distinction between when() and then() in REST Assured lies in their specific roles within the framework's fluent interface for testing HTTP APIs. When you use when(), you are preparing to perform an action, such as sending a request to the server. This method is where you specify the HTTP method (GET, POST, PUT, DELETE, etc.) and the endpoint you want to interact with. It's essentially about setting up the context of your test and making the API call.

Conversely, then() is used to assert the results of the action that was defined by when(). After the API call has been made, then() allows you to specify various assertions to verify the response against expected outcomes. This might include checking the status code, validating the response body, or ensuring that certain headers are present.

Therefore, the correct answer effectively describes how when() focuses on the action of sending a request, whereas then() is concerned with verifying and asserting the outcomes of that request.

Subscribe

Get the latest from Examzify

You can unsubscribe at any time. Read our privacy policy