{"id":16536660,"url":"https://github.com/eliasnogueira/restassured-complete-basic-example","last_synced_at":"2025-04-12T16:42:34.587Z","repository":{"id":41526328,"uuid":"282194406","full_name":"eliasnogueira/restassured-complete-basic-example","owner":"eliasnogueira","description":"A complete API Test Architecture example using Java and RestAssured providing a real-world example and continuous delivery ready.","archived":false,"fork":false,"pushed_at":"2025-03-31T19:32:52.000Z","size":283,"stargazers_count":212,"open_issues_count":0,"forks_count":97,"subscribers_count":9,"default_branch":"main","last_synced_at":"2025-04-03T19:15:40.696Z","etag":null,"topics":["apitesting","java","restassured","testautomation"],"latest_commit_sha":null,"homepage":"http://eliasnogueira.com","language":"Java","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/eliasnogueira.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.md","contributing":"CONTRIBUTING.md","funding":null,"license":"LICENSE","code_of_conduct":"CODE_OF_CONDUCT.md","threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2020-07-24T10:47:09.000Z","updated_at":"2025-04-02T22:20:13.000Z","dependencies_parsed_at":"2023-11-07T01:49:42.301Z","dependency_job_id":"625e5149-6b72-4826-a601-f112365506a5","html_url":"https://github.com/eliasnogueira/restassured-complete-basic-example","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/eliasnogueira%2Frestassured-complete-basic-example","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/eliasnogueira%2Frestassured-complete-basic-example/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/eliasnogueira%2Frestassured-complete-basic-example/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/eliasnogueira%2Frestassured-complete-basic-example/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/eliasnogueira","download_url":"https://codeload.github.com/eliasnogueira/restassured-complete-basic-example/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":248599297,"owners_count":21131257,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["apitesting","java","restassured","testautomation"],"created_at":"2024-10-11T18:32:38.249Z","updated_at":"2025-04-12T16:42:34.565Z","avatar_url":"https://github.com/eliasnogueira.png","language":"Java","readme":"# Rest-Assured Complete Basic Example\n[![Actions Status](https://github.com/eliasnogueira/restassured-complete-basic-example/workflows/Build%20and%20Test/badge.svg)](https://github.com/eliasnogueira/restassured-complete-basic-example/actions)\n\nDon't forget to give this project a ⭐\n\n* [Required Software](#required-software)\n* [How to execute the tests](#how-to-execute-the-tests)\n   * [Running the backend API](#running-the-backend-api)\n   * [Running the test suites](#running-the-test-suites)\n   * [Generating the test report](#generating-the-test-report)\n* [About the Project Structure](#about-the-project-structure)\n* [Libraries](#libraries)\n* [Patterns applied](#patterns-applied)\n* [Pipeline](#pipeline)\n* [Do you want to help?](#do-you-want-to-help)\n\nThis project was created to start the initial steps with test automation for a REST API using Rest-Assured.\nIt tests the API: [combined-credit-api](https://github.com/eliasnogueira/combined-credit-api)\n\n\u003e :warning: **Disclaimer**\n\u003e \n\u003e This project has an educational objective and does not have the best practices that could be applied\n\u003e\n\u003e Some practices will help you to improve your test architecture, but the central point of this repository and \n\u003e demonstrate an example of running tests for API in a pipeline\n\u003e some practices will help you to improve your test architecture, \n\u003e but the central point of this repository and demonstrate an example of running tests for API in a pipeline\n\n## Required software\n* Java JDK 24+\n* Maven installed and in your classpath\n* Clone/download the backend API [combined-credit-api](https://github.com/eliasnogueira/combined-credit-api)\n\n\u003e :notebook: **Note**\n\u003e\n\u003e You can use Java 17 if you want\n\n\n## How to execute the tests\nYou can open each test class on `src\\test\\java` and execute all of them, but I recommend you run it by the\ncommand line. It enables us to run in different test execution strategies and, also in a pipeline, that is the repo purpose.\n\n### Running the backend API\nPlease, before executing any tests, run the backend API.\nAfter cloning this project:\n\n1. Navigate to the project folder using the Terminal / Command prompt\n2. Execute the following: `./mvnw spring-boot:run`\n3. Wait until you see something like this: _Application has started! Happy tests!_\n4. The API is ready and listen to all requests on `http://localhost:8088`\n\n### Running the test suites\n\nThe test suites can be run directly by your IDE or by command line.\nIf you run `./mvnw test` all the tests will execute because it's the regular Maven lifecycle to run all the tests.\n\nTo run different suites based on the groups defined for each test you must inform the property `-Dgroups` and the group names.\nThe example below shows how to run the test for each pipeline stage:\n\n| pipeline stage     | command                             |\n|--------------------|-------------------------------------|\n| health check tests | `./mvnw test -Dgroups=\"health\"`     |\n| contract tests     | `./mvnw test -Dgroups=\"contract\"`   |\n| functional tests   | `./mvnw test -Dgroups=\"functional\"` |\n| e2e tests          | `./mvnw test -Dgroups=\"e2e\"`        |\n\n### Generating the test report\n\nThis project uses Allure Report to automatically generate the test report.\nThere are some configuration to make it happen:\n* aspectj configuration on `pom.xml` file\n* `allure.properties` file on `src/test/resources`\n\nYou can use the command line to generate it in two ways:\n* `./mvnw allure:serve`: will open the HTML report into the browser\n* `./mvnw allure:report`: will generate the HTML port at `target/site/allure-maven-plugin` folder\n\n## About the Project Structure\n\n### src/main/java\n\n#### test\nBase Test that sets the initial aspects to make the requests using RestAssured.\nIt also has the configuration to deal with `BigDecimal` returns and SSL configuration.\n\n#### client\nClasses that do some actions in their endpoints. It's used my the `FullSimulationE2ETest` to demonstrate and e2e\nscenario.\n\n#### commons\nIt contains a class where will format the URL expected when we create a new resource in the `simulation` endpoint.\nYou can add any class that can be used in the project.\n\n#### config\nThe class `Configuration` is the connections between the property file `api.properties` located in `src/test/resources/`.\n\nThe `@Config.Sources` load the properties file and match the attributes with the `@Key`, so you automatically have the value.\nYou can see two sources.\nThe first one will get the property values from the system (as environment variables or from the command line) in the case you want to change it, for example, in a pipeline.\nThe second will load the `api.properties` file from the classpath.\n```java\n@Config.Sources({\n    \"system:properties\",\n    \"classpath:api.properties\"})\n```\n\nThe environment variable is read on the `ConfiguratorManager`.\nThis class reduces the amount of code necessary to get any information on the properties file.\n\nThis strategy uses [Owner](https://matteobaccan.github.io/owner/) library\n\n#### data\n\n##### factory\nTest Data Factory classes using [java-faker](https://github.com/DiUS/java-faker) to generate fake data and [Lombok] to\ncreate the objects using the Builder pattern.\n\nIn a few cases, there are custom data like:\n * the list of existent restrictions and simulations in the database\n * cpf generation\n * data generation returned by the API use\n\n##### provider\nJUnit 5 Arguments to reduce the amount of code and maintenance for the functional tests on `SimulationsFunctionalTest`\n\n##### suite\nIt contains a class having the data related to the test groups.\n\n##### support\nCustom CPF (social security number) generator.\n\n#### model\nModel and Builder class to\n[mapping objects thought serialization and deserialization](https://github.com/rest-assured/rest-assured/wiki/Usage#object-mapping) \nin use with Rest-Assured.\n\n#### specs\nRequest and Response specifications used by the clients and e2e tests.\nThe class `InitialStepsSpec` set the basePath, baseURI, and port for the custom specs.\nThe classes `RestrictionsSpecs` and `SimulationsSpecs` contains the implementation of request and response specifications.\n\n### src/test/java\n\n#### e2e\nEnd-to-End test using both endpoints to simulate the user journey thought the API.\n\n#### general\nHealth check test to assure the endpoint is available.\n\n#### restrictions\nContract and Functional tests to the Restriction endpoint.\n\n#### simulations\nContract and Functional tests to the Simulations endpoint\n\n### src/test/resources\nIt has a `schemas` folder with the JSON Schemas to enable Contract Testing using Rest-Assured. Also, the properties file to easily configure the API URI.\n\n## Libraries\n* [RestAssured](http://rest-assured.io/) library to test REST APIs\n* [JUnit 5](https://junit.org/junit5/) to support the test creation\n* [Owner](https://matteobaccan.github.io/owner/) to manage the property files\n* [java-faker](https://github.com/DiUS/java-faker) to generate fake data\n* [Log4J2](https://logging.apache.org/log4j/2.x/) as the logging strategy\n* [Allure Report](https://docs.qameta.io/allure/) as the testing report strategy\n\n## Patterns applied\n* Test Data Factory\n* Data Provider\n* Builder\n* Request and Response Specification\n* Base Test\n\n## Pipeline\n\nThis project uses [GitHub Actions](https://github.com/features/actions) to run the all the tests in a pipeline.\nYou can find it at https://github.com/eliasnogueira/restassured-complete-basic-example/blob/master/.github/workflows/test-execution.yml\n\nWe have the following pipeline steps:\n```\nbuild -\u003e health check -\u003e contract -\u003e e2d -\u003e funcional \n```\n\nExcept the build, that is the traditional Maven build, the other stages has some parameters to determine the test type and the SUT (System Under Test).\nThe parameters are:\n* `-Dgroups`: specify which test type will be executed\n* `-Dapi.base.uri`: specify a new base URI\n* `-Dapi.base.path`: specify a new base path\n* `-Dapi.port`: specify a new port\n* `-Dapi.health.context`: specify a new health context\n\nAll the parameters, except the `-Dgroups` are pointing to Heroku because we can't run it locally.\nIt's a great example about how can you set different attribute values to run your tests.\n\n## Do you want to help?\n\nPlease read the [Contribution guide](CONTRIBUTING.md)\n","funding_links":[],"categories":[],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Feliasnogueira%2Frestassured-complete-basic-example","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Feliasnogueira%2Frestassured-complete-basic-example","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Feliasnogueira%2Frestassured-complete-basic-example/lists"}