3

I'm currently looking at building an API test automation framework for a series of Rest Services, utilising c#. Coming from a UI-automation background I was after some advise on assertions when testing against an API.

Obviously there are a whole array of different assertions that can be carried out but based on peoples experiences are there certain assertions that must be done? e.g. that the Expected Status Code is returned? Or is this something that can only be ascertained once the API definitions are in place?

asked Sep 7, 2018 at 13:17

2 Answers 2

1

That depends on what exactly you're going to test. If you're going to test only API logic, then you should assert

  • Response codes
  • Response body (since API methods often return objects within the body)
  • Less likely but: assert the API response time

If you want to verify how HTTP server (that manages the requests and responses) works in combination with your API you would probably need to implement assertions of HTTP headers. It also worth implementing assertion of a raw response so that the user of your framework will be able to assert raw response with regular expressions for example.

answered Sep 7, 2018 at 14:01
3
  • Thanks Alexey. the lower level detail has yet to be defined but my understanding is that it will just be API logic Commented Sep 7, 2018 at 14:07
  • @AndyTilston I added api response time assertion as well. Commented Sep 7, 2018 at 14:08
  • And you might check some releveant HTTP headers as well, like Content-Type: application/json; charset=utf-8. Commented Sep 7, 2018 at 14:23
0

I would certainly check for HTTP status codes, for instance when input data is invalid (400), user is not authorized (401) or method (GET/PUT/POST) is not allowed (405).

answered Sep 7, 2018 at 13:42

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

By clicking "Post Your Answer", you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.