0

I have a situation whereby, say, I have one API which creates an employee(POST); one which then returns the employee(GET) and one which deletes the employee(DELETE).

I've been using RestSharp/C# to create my API tests which I've found really useful, however I'm struggling to understand how I'd create a test like the above where I'd want to test multiple API's as part of the one test so that I can ensure the creation and deletion works as expected. For example, I'd pass the Name as a parameter from the "create employee" API and ensure it is returned in the GET request.

If anyone has any advice or working examples of this, it would be very useful

3 Answers 3

1

You could use BDD #Cucumber here. Given, When, Then keywords are its keywords. In Given step method trigger API POST to create the user. In When step method, trigger GET to retrieve user details. In Then step method, delete the user. This way your scenario as well as your testing looks complete

-1

You could create (or delete) a particular user directly in your database as a part of the test set up. That way you avoid using the very calls you are trying to test. You can also delete the user as a part of tear down of the test.

So for testing GET in your case, create a user during set up, send the GET request and delete the user in the tear down. For CREATE, send POST and delete the user in the tear down. For DELETE, during set up insert the user directly into the database and make the DELETE request.


Edit:

Sorry, I misread your question earlier. If you want to test it all in one go, you could CREATE a user with one call, GET it and then DELETE it.

However, if something goes wrong, you won't be able to pinpoint the actual bug.

I`d create separate tests anyway. If you really want to include all of these in one test, I would suggest you insert 2 users into the database (one each for GET and DELETE) and CREATE another one with the request.

1
  • To add to @Dan's answer, you want to separate the tests as part of the TDD F.I.R.S.T. principle. You can test DELETE with a seeded user and not have to call POST first (which you aren't testing in that Test Case).
    – kirbycope
    Commented Sep 20, 2018 at 18:54
-1
  1. POST Create Employee
  2. GET Employee Created
  3. PUT Update Employee
  4. GET Employee Updated
  5. DELETE Employee
  6. GET Employee, make sure it is no longer available
1
  • 1
    You could do a GET first to make it doesn't exist (yet). :)
    – FDM
    Commented Sep 22, 2018 at 11:58

Your Answer

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

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