Start E2E API testing with just 4 commands

·

2 min read

Let’s get you up and running with E2E API tests with just 4 commands. Follow the steps below to get started with E2E API testing using RestAssured. If you’re starting out, check out my earlier articles to get a better sense of this is built.

Before you start, ensure the prerequisites below are satisfied:

  • Java 21 is installed, you can follow this guide for installation instructions.

  • Maven is installed, you can follow this guide for installation instructions.

TL;DR: copy and paste the commands below.

:~$ git clone https://github.com/tinashec/maven-archetype-api-tests.git
:~$ cd maven-archetype-api-tests/; mvn install
:~$ cd ..; mvn archetype:generate -DarchetypeGroupId=org.example -DarchetypeArtifactId=api-test-archetype -DarchetypeVersion=1.0-SNAPSHOT -DartifactId=api-test
:~$ cd api-test/; mvn test
  1. Clone the repo:

    In your terminal, run the command:

     git clone https://github.com/tinashec/maven-archetype-api-tests.git
    

    NB: make sure you have Git installed on your local machine. See this guide for Git installation.

  2. Install the archetype

    Navigate to the root of the cloned project i.e. cd maven-archetype-api-tests/ and run the command

     mvn install
    

    You should see the BUILD SUCCESS message

  3. Generate the project

    Navigate to your preferred project location (outside of the cloned project repo). Run the command:

     mvn archetype:generate -DarchetypeGroupId=org.example -DarchetypeArtifactId=api-test-archetype -DarchetypeVersion=1.0-SNAPSHOT -DartifactId=api-test
    

    This will prompt for details of the project, you can use the values below

     Define value for property 'groupId': e.g. com.my_company_name
     Define value for property 'version' 1.0-SNAPSHOT: e.g. 1.0
     Define value for property 'package' {{groupId}}: e.g. e2e.apitest
     Confirm properties configuration: Type yes i.e. y
    
  4. Run the test

    Navigate to the newly created project/repo cd api-test/ and run the command:

     mvn test
    

This will run the pre-configured test, sending a POST request to the restful-booker endpoint. The request and response are logged in the terminal.

That’s it, you’ve configured and sent an API request using RestAssured. You can install Allure for a clean reporting interface. With Allure installed, you’ll run the command:

allure serve

This will open the test results in a browser window.

Next steps

Open the project and tweak it to meet your requirements. You can go through one of my earlier articles to see how to think about writing automated E2E API tests.

Congratulations, you’ve set up and run a test using RestAssured.

Happy testing!