2

For Selenium usually Page Object Model is used. What are good design patterns for REST Assured to organize structure, files?

2

Here's a number of design patterns you can use for testing REST services (with REST-assured, but not necessarily*):

  • Service Object pattern. Just like Page Object encapsulates HTML page, Service Object encapsulates REST API. Hence, instead of dealing directly with forming HTTP requests and parsing HTTP responses, you can use business level methods like LoginService.login() that will handle translation for yourself. Retrofit provides great implementation of this pattern, although you can encapsulate REST-assured calls into Service Objects as well.
  • Scenario Object pattern. If you have multiple services often used together, e.g., LoginAsAdminService, CreateUserService and GrantPermissionsService you can chain them together into CreateUserWithPermissionsScenario.
  • Service Mock Object is a generalization of Mock Object pattern to service-oriented systems. WireMock and MockServer are notable implementations of it in Java world.

You can also incorporate general design patterns, e.g.:

  • Decorator patterns to add injecting of authorization token to each of your HTTP requests
  • Template method pattern to have parent abstract service that provides authentication mechanism with abstract send() method that specific implementation of this service (classes inheriting from it) implement.

I recommend you reading "Design Patterns: Elements of Reusable Object-Oriented Software" book to learn more about design patterns.

*REST-assured is just one of many HTTP clients on the market, so what I presented are examples for design patterns you can use for testing REST API with any HTTP client.

0

That depend from the size of the project, with a large code base with multiple modules it might be appropriate to create a folder Service and then a class for each module like you will normally do with tests for the UI, but for a small project even a single Class(eg called RestApi) can be sufficient, so basically the same logic of POM still apply for structure and organisation of files the main difference is that rather than test the application from UI(clicking buttons that call API) you test directly the API.

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.