Skip to content

Instantly share code, notes, and snippets.

@eliasnogueira
Last active November 28, 2023 22:08
Show Gist options
  • Star 2 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save eliasnogueira/65853cade44d6aab4e3005fae4b71a9b to your computer and use it in GitHub Desktop.
Save eliasnogueira/65853cade44d6aab4e3005fae4b71a9b to your computer and use it in GitHub Desktop.

Title

Build robust API tests with RestAssured

Description

This workshop will show you how to use a different approach from SpringTest or any other tool to build robust API tests in the integration later or intra-services.

Rest-Assured is a well-known Java DSL for testing REST services, giving software engineers a lot of freedom during the test automation process creation.

The workshop will start with the RestAssured basics and how we can use any REST API methods in a test, followed by some features such as authentication, request and response specification, and authentication.

After all the basic approaches you will learn how to apply some design and testing patterns such as Base Test Class and Test Data Factory to remove all code duplication. To enable a more robust architecture you will learn how to create abstraction on top of the auto-generated client code, creating a service abstraction to deal with different requests. This will allow you to extend the API test coverage and think about integration tests without mocks!

Steps

This will be what you will learn during the workshop:

  • Basic Rest-Assured concepts
  • Request and Response specifications
  • Filters
  • How to automate any test given the REST API methods
  • How to deal with authentication
  • How to build a robust framework for intra-service testing using:
    • OpenAPI library to generate the client code
    • Abstractions for REST configuration, client definition, and service definition

Tools

  • Java 17
  • RestAssured as the API test library
  • AssertJ as the assertion library
  • DataFaker as data generation
  • a SpringBoot application to test

Necessary equipment

  • Laptop
  • JDK 17 installed
  • Any IDE
  • Partial internet access is required (only to download the libraries for the first time)

Takeaways

  • Learn how to test microservices with the possibility of easily extending their coverage
  • Have a full workable example to reproduce at work
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment