jeudi 25 juin 2020

Is this a correct approach to integration test a RESTful Web API/Service?

I'm currently working on a Spring Boot CRUD RESTful API with an User entity that consists of two parameters : name and id. Its endpoints are :

  • POST REQUEST IN /users - Create an user
  • GET REQUEST IN /users/{id} - List a specific user by its id
  • GET REQUEST IN /users - List all users
  • PUT REQUEST IN /users/{id} - Update a specific user by its id
  • DELETE REQUEST IN /users/{id} - Delete a specific user by its id

Each endpoint is built with a controller and a service to implement its logic.

I've already wrote unit tests for my controllers and services, now i'm trying to build integration tests to assert that my endpoints work properly as a group of components.

The way i'm thinking of doing this is by calling all endpoints through a series of steps :

  1. Create an user through the create endpoint endpoint called testUserOne and an user called testUserTwo and assert that they were created
  2. List all users through the list all users endpoint and assert that both users were listed
  3. Change name parameter of testUserOne through the update endpoint and assert it was changed
  4. Remove testUserTwo through the delete endpoint and assert it was removed
  5. List all users through the list all users endpoint and assert that only testUserOne was listed with its updated name parameter
  6. List testUserOne through the list an specific user endpoint and assert it was listed with its updated name parameter

No mocking involved, all this will be done by calling the real repository and asserting that every operation was executed and every response checked with its expected value.

This is the way i'm thinking of approaching this endpoints integration test, since it's my first time doing this, i'm hoping for some tips and guidance from the Stack Overflow community. Thank you!

Aucun commentaire:

Enregistrer un commentaire