A framework for e2e API Tests

A framework for e2e API Tests

·

2 min read

I’ve always been fascinated by people who build libraries or develop solutions that others rely on. On the one hand, I’ve viewed these individuals as people with uncommon ability and superhuman intelligence. On the other, I’ve read it’s all about consistency, being open-minded, and adopting Kaizen.

My personal experience has shown the latter to hold true. I’m not an individual with uncommon ability or superhuman intelligence, but here I am publishing a solution that has helped me when faced with E2E Test framework setup. I’ve had requests to create automated test frameworks several times. I’ve made the same a couple of times before as well. These experiences inspired me to design and publish a template that I can use when the need arises.

The challenge

If you’ve created a framework from scratch, you’ll understand that there are a number of components to consider.

  • Which test framework to use (TestNG/jUnit)

  • Which REST client to adopt?

  • How to generate the reports?

  • Which software build management solution (Gradle or Maven) is ideal?

  • Will the tests be data-driven?

  • What is the structure of the project itself - where do the test classes go, where do I put the endpoints, and where do I put the payload?

All these considerations make for a daunting task if you’re looking to automate E2E API tests.

The solution: A Maven Archetype

Maven archetypes (a project templating toolkit) enables authors to create project templates that allow testers/developers to get up and running quickly. Using this powerful tool, I’ve built a Maven archetype specifically for setting up E2E API testing projects. This archetype should enable setting up E2E API tests with a couple of commands, by my count 3.

It’s designed to eliminate the repetitive setup process, letting you focus on writing effective tests right away. This archetype will generate:

  • a pre-configured directory structure

      api-test
      |-- pom.xml
      `-- src
          |`-- main
          |   `-- java
          |     `-- e2e-api-test
          `-- test
              `-- java
                  `-- e2e-api-test
                       `-- endpoints
                       `-- model
                       `-- payload
                       `-- utils
    
  • add dependencies for TestNG, Allure, RestAssured, Hamcrest etc.

  • the endpoints and payload for a sample request

  • a sample test that leverages the restful-booker endpoint

If you're looking to streamline your API testing workflow, the archetype might just be the solution you need. Do reach out if you’ve got any questions or contributions.

Happy Testing!