1

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?

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.

  • Thanks Alexey. the lower level detail has yet to be defined but my understanding is that it will just be API logic – Andy Tilston Sep 7 '18 at 14:07
  • @AndyTilston I added api response time assertion as well. – Alexey R. Sep 7 '18 at 14:08
  • And you might check some releveant HTTP headers as well, like Content-Type: application/json; charset=utf-8. – Bouke Sep 7 '18 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).

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.