{"id":21582687,"url":"https://github.com/automation-test-starter/restassured-api-test-starter","last_synced_at":"2025-05-01T09:55:00.580Z","repository":{"id":203491384,"uuid":"709686621","full_name":"Automation-Test-Starter/RestAssured-API-Test-Starter","owner":"Automation-Test-Starter","description":"An introductory document on using RestAssured for API testing.","archived":false,"fork":false,"pushed_at":"2023-11-19T12:59:37.000Z","size":503,"stargazers_count":7,"open_issues_count":0,"forks_count":2,"subscribers_count":2,"default_branch":"main","last_synced_at":"2025-05-01T09:54:54.397Z","etag":null,"topics":["all","allure","allure-report","api-testing","demo","gradle","java","maven","quickstart","restassured","test-automation"],"latest_commit_sha":null,"homepage":"","language":null,"has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"apache-2.0","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/Automation-Test-Starter.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"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":"2023-10-25T07:39:38.000Z","updated_at":"2025-03-26T21:59:00.000Z","dependencies_parsed_at":"2023-11-19T13:50:50.176Z","dependency_job_id":null,"html_url":"https://github.com/Automation-Test-Starter/RestAssured-API-Test-Starter","commit_stats":null,"previous_names":["automation-test-starter/restassured-api-test-starter"],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Automation-Test-Starter%2FRestAssured-API-Test-Starter","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Automation-Test-Starter%2FRestAssured-API-Test-Starter/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Automation-Test-Starter%2FRestAssured-API-Test-Starter/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Automation-Test-Starter%2FRestAssured-API-Test-Starter/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/Automation-Test-Starter","download_url":"https://codeload.github.com/Automation-Test-Starter/RestAssured-API-Test-Starter/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":251856993,"owners_count":21655119,"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":["all","allure","allure-report","api-testing","demo","gradle","java","maven","quickstart","restassured","test-automation"],"created_at":"2024-11-24T14:16:34.540Z","updated_at":"2025-05-01T09:55:00.548Z","avatar_url":"https://github.com/Automation-Test-Starter.png","language":null,"funding_links":[],"categories":[],"sub_categories":[],"readme":"\u003c!-- markdownlint-disable MD041 --\u003e\n\u003c!-- markdownlint-disable MD033 --\u003e\n\u003cdiv align=\"right\"\u003e\u003cstrong\u003e\u003ca href=\"./README_ZH.md\"\u003e🇨🇳中文\u003c/a\u003e\u003c/strong\u003e  | \u003cstrong\u003e🇬🇧English\u003c/strong\u003e\u003c/div\u003e\n\u003c!-- markdownlint-disable MD041 --\u003e\n\u003c!-- markdownlint-disable MD033 --\u003e\n\n# RestAssured-API-Test-Starter\n\nIntroductory documentation for a quick-start project on API testing with RestAssured.\n\n- [RestAssured-API-Test-Starter](#restassured-api-test-starter)\n  - [Introduction of RestAssured](#introduction-of-restassured)\n  - [Project structure](#project-structure)\n    - [Gradle-built versions](#gradle-built-versions)\n    - [Maven-built versions](#maven-built-versions)\n  - [Project dependency](#project-dependency)\n  - [Building a REST Assured API test project from 0 to 1](#building-a-rest-assured-api-test-project-from-0-to-1)\n    - [Gradle version](#gradle-version)\n      - [Initialize an empty Gradle project](#initialize-an-empty-gradle-project)\n      - [Configuration build.gradle](#configuration-buildgradle)\n      - [testng.xml configuration](#testngxml-configuration)\n      - [gradle build project and initialize](#gradle-build-project-and-initialize)\n      - [initialization project directory](#initialization-project-directory)\n      - [Introduction of demo test API](#introduction-of-demo-test-api)\n        - [Get API](#get-api)\n        - [Post API](#post-api)\n      - [Writing Test cases](#writing-test-cases)\n      - [Debugging test cases](#debugging-test-cases)\n      - [Viewing Test Reports](#viewing-test-reports)\n        - [Command Line Report](#command-line-report)\n        - [testng html Report](#testng-html-report)\n    - [Maven version](#maven-version)\n      - [Initialize an empty Maven project](#initialize-an-empty-maven-project)\n      - [Configuration pom.xml](#configuration-pomxml)\n      - [Configuration testng.xml](#configuration-testngxml)\n      - [initialization maven project directory](#initialization-maven-project-directory)\n      - [The api used by Demo](#the-api-used-by-demo)\n      - [Writing Test cases](#writing-test-cases-1)\n      - [Debugging test cases](#debugging-test-cases-1)\n      - [Viewing Test Reports](#viewing-test-reports-1)\n        - [terminal report](#terminal-report)\n        - [testng html report](#testng-html-report-1)\n  - [Advanced Usage](#advanced-usage)\n    - [Verifying Response Data](#verifying-response-data)\n      - [response body assertion](#response-body-assertion)\n        - [json assertion](#json-assertion)\n        - [XML assertion](#xml-assertion)\n      - [Cookie assertion](#cookie-assertion)\n      - [Status Code Assertion](#status-code-assertion)\n      - [Header Assertion](#header-assertion)\n      - [Content-Type Assertion](#content-type-assertion)\n      - [Full body/content matching Assertion](#full-bodycontent-matching-assertion)\n      - [Measuring Response Time](#measuring-response-time)\n    - [File Upload](#file-upload)\n    - [Logging](#logging)\n      - [Global logging configuration](#global-logging-configuration)\n        - [Steps to add global logging configuration](#steps-to-add-global-logging-configuration)\n        - [Global Logging Code Example](#global-logging-code-example)\n        - [Viewing Global Log Output](#viewing-global-log-output)\n      - [Localized logging configuration](#localized-logging-configuration)\n        - [Steps to add Localized logging configuration](#steps-to-add-localized-logging-configuration)\n        - [Viewing Localized Log Output](#viewing-localized-log-output)\n      - [LogConfig Configuration Description](#logconfig-configuration-description)\n      - [Request Logging](#request-logging)\n      - [Response Logging](#response-logging)\n      - [Log if validation fails](#log-if-validation-fails)\n      - [Header Blacklist Configuration](#header-blacklist-configuration)\n    - [Filters](#filters)\n      - [Ordered Filters](#ordered-filters)\n      - [Response Builder](#response-builder)\n    - [CI/CD integration](#cicd-integration)\n      - [integration github action](#integration-github-action)\n        - [The Gradle version integration github action](#the-gradle-version-integration-github-action)\n        - [The Maven version integration github action](#the-maven-version-integration-github-action)\n    - [Integrating allure test reports](#integrating-allure-test-reports)\n      - [allure Introduction](#allure-introduction)\n      - [Integration steps](#integration-steps)\n        - [The Maven version integration of allure](#the-maven-version-integration-of-allure)\n        - [The Gradle version of allure integration](#the-gradle-version-of-allure-integration)\n  - [Reference](#reference)\n\n## Introduction of RestAssured\n\nREST Assured is a Java testing framework for testing RESTful APIs that enables developers/testers to easily write and execute API tests. It is designed to make API testing simple and intuitive, while providing rich functionality and flexibility. The following are some of the key features and uses of REST Assured:\n\n1. Initiating HTTP requests: REST Assured allows you to easily build and initiate HTTP GET, POST, PUT, DELETE and other types of requests. You can specify the request's URL, headers, parameters, body, and other information.\n\n2. Chained Syntax: REST Assured uses chained syntax to make test code more readable and easy to write. You can describe your test cases in a natural way without writing tons of code.\n\n3. Assertions and Checksums: REST Assured provides a rich set of checksums that can be used to validate API response status codes, response bodies, response headers, and so on. You can add multiple assertions according to your testing needs.\n\n4. Support for multiple data formats: REST Assured supports a variety of data formats, including JSON, XML, HTML, Text and so on. You can use appropriate methods to handle different formats of response data.\n\n5. Integration with BDD (Behavior-Driven Development): REST Assured can be used in conjunction with BDD frameworks (such as Cucumber), allowing you to better describe and manage test cases.\n\n6. Simulate HTTP Server: REST Assured also includes a simulation of an HTTP server, allowing you to simulate the behavior of an API for end-to-end testing.\n\n7. Extensibility: REST Assured can be customized with plug-ins and extensions to meet specific testing needs.\n\nOverall, REST Assured is a powerful and easy-to-use API testing framework that helps you easily perform RESTful API testing and provides many tools to verify the correctness and performance of an API. Whether you are a beginner or an experienced developer/tester, REST Assured is a valuable tool for quickly getting started with API automation testing.\n\n## Project structure\n\n### Gradle-built versions\n\n```text\n- src\n  - main\n    - java\n      - (The main source code of the application)\n  - test\n    - test\n      - api\n        - (REST Assured test code)\n          - UsersAPITest.java\n          - ProductsAPITest.java\n        - TestConfig.java\n          - TestConfig.java\n    - resources\n      - (configuration files, test data, etc.)\n  - (other project files and resources)\n- build.gradle (Gradle project configuration file)\n```\n\nIn this example directory structure:\n\n- src/test/java/api directory is used to hold REST Assured test classes, each of which typically involves tests for one or more related API endpoints. For example, UsersAPITest.java and ProductsAPITest.java could contain tests for user management and product management.\n- The src/test/java/util directory can be used to store tool classes that are shared among tests, such as TestConfig.java for configuring REST Assured.\n- The src/test/resources directory can contain test data files, configuration files, and other resources that can be used in tests.\n- build.gradle is the gradle project's configuration file, which is used to define the project's dependencies, build configuration, and other project settings.\n\n### Maven-built versions\n\n```text\n- src\n  - main\n    - java\n      - (The main source code of the application)\n  - test\n    - java\n      - api\n        - (REST Assured test code)\n          - UsersAPITest.java\n          - ProductsAPITest.java\n        - util\n          - TestConfig.java\n    - resources\n      - (configuration files, test data, etc.)\n  - (other project files and resources)\n- pom.xml (Maven project configuration file)\n```\n\nIn this example directory structure:\n\n- src/test/java/api directory is used to hold REST Assured test classes, each of which typically involves tests for one or more related API endpoints. For example, UsersAPITest.java and ProductsAPITest.java could contain tests for user management and product management.\n- The src/test/java/util directory can be used to store tool classes that are shared among tests, such as TestConfig.java for configuring REST Assured.\n- The src/test/resources directory can contain test data files, configuration files, and other resources that can be used in the tests.\n- pom.xml is a Maven project configuration file that is used to define project dependencies, build configurations, and other project settings.\n\n## Project dependency\n\n- JDK 1.8+, I'm using JDK 19\n- Gradle 6.0+ or Maven 3.0+, I'm using Gradle 8.44 and Maven 3.9.5\n- RestAssured 4.3.3+, I'm using the latest version 5.3.2\n\n## Building a REST Assured API test project from 0 to 1\n\nREST Assured supports both Gradle and Maven build tools, you can choose one of them according to your preference. Below is a description of the initialization process for Gradle and Maven build tools.\n\nThis project is built using Gradle 8.44 and Maven 3.9.5, if you are using other versions, it may be different.\n\n### Gradle version\n\nSee the demo project at \u003chttps://github.com/Automation-Test-Starter/RestAssured-gradle-demo\u003e.\n\n#### Initialize an empty Gradle project\n\n```bash\nmkdir RestAssured-gradle-demo\ncd RestAssured-gradle-demo\ngradle init\n```\n\n#### Configuration build.gradle\n\nThe demo project introduces the testNG testing framework. For reference only.\n\n- Create a build.gradle file in the project root directory to configure the project.\n- For reference, the following is a sample configuration\n\n```groovy\n// plugins configuration\nplugins {\n    id 'java' // use java plugin\n}\n\n// repositories configuration\nrepositories {\n  mavenCentral() // user maven central repository\n}\n\n// dependencies configuration\ndependencies {\n    testImplementation 'io.rest-assured:rest-assured:5.3.1' // add rest-assured dependency\n    testImplementation 'org.testng:testng:7.8.0' // add testng testing framework dependency\n    implementation 'org.uncommons:reportng:1.1.4' // add testng reportng dependency\n    implementation 'org.slf4j:slf4j-api:2.0.9' // add slf4j dependency for test logging\n    implementation 'org.slf4j:slf4j-simple:2.0.9' // add slf4j dependency for test logging\n    implementation group: 'com.google.inject', name: 'guice', version: '7.0.0'\n}\n\n// test configuration\ntest {\n    reports.html.required = false // set gradle html report to false\n    reports.junitXml.required = false // set gradle junitXml report to false\n    // use testng testing framework\n    useTestNG() {\n        useDefaultListeners = true\n        suites 'src/test/resources/testng.xml' // set testng.xml file path\n    }\n    testLogging.showStandardStreams = true // output test log to console\n    testLogging.events \"passed\", \"skipped\", \"failed\" // deny output test log to console\n}\n```\n\n\u003e You can copy the contents of the build.gradle file in this project. For more configuration refer to [Official Documentation](https://github.com/rest-assured/rest-assured/wiki/GettingStarted#rest-assured)\n\n#### testng.xml configuration\n\n- Create a resources directory under the src/test directory to store test configuration files.\n\n- Create a testng.xml file in the resources directory to configure the TestNG test framework.\n\n- For reference, the following is a sample configuration\n\n```xml\n\u003c?xml version=\"1.0\" encoding=\"UTF-8\"?\u003e\n\u003c!DOCTYPE suite SYSTEM \"http://testng.org/testng-1.0.dtd\"\u003e\n\u003csuite name=\"restAssured-gradleTestSuite\"\u003e\n\u003ctest thread-count=\"1\" name=\"Demo\"\u003e\n    \u003cclasses\u003e\n        \u003cclass name=\"com.example.TestDemo\"/\u003e \u003c!-- test case class--\u003e\n    \u003c/classes\u003e\n\u003c/test\u003e \u003c!-- Test --\u003e\n\u003c/suite\u003e \u003c!-- Suite --\u003e\n```\n\n#### gradle build project and initialize\n\n- Open the Terminal window of the project with an editor and execute the following command to confirm that the project build was successful\n\n```bash\ngradle build\n```\n\n- Initialization complete: After completing the wizard, Gradle will generate a basic Gradle project structure in the project directory\n  \n#### initialization project directory\n\nThe directory structure can be found in \u003e\u003e [Project structure](#project-structure)\n\nCreate a new test class in the project's test source directory. By default, Gradle usually places the test source code in the src/test/java directory. You can create a package of test classes in that directory and create a new test class in the package\n\nTo create a test class for TestDemo, you can create files with the following structure\n  \n```text\nsrc\n└── test\n    └── java\n        └── com\n            └── example\n                └── TestDemo.java\n```\n\n#### Introduction of demo test API\n\n##### Get API\n\n- HOST: https://jsonplaceholder.typicode.com\n- API path: /posts/1\n- Request method: GET\n- Request Parameters: None\n- Request header: \"Content-Type\": \"application/json; charset=utf-8\"\n- Request Body: None\n- Response status code: 200\n- Response header: \"Content-Type\": \"application/json; charset=utf-8\"\n- Response body:\n\n```json\n{\n    \"userId\": 1,\n    \"id\": 1,\n    \"title\": \"sunt aut facere repellat provident occaecati excepturi optio reprehenderit\",\n    \"body\": \"quia et suscipit\\nsuscipit recusandae consequuntur expedita et cum\\nreprehenderit molestiae ut ut quas totam\\nnostrum rerum est autem sunt rem eveniet architecto\"\n}\n```\n\n##### Post API\n\n- HOST: https://jsonplaceholder.typicode.com\n- API path:/posts\n- Request method: POST\n- Request Parameters: None\n- Request header:\"Content-Type\": \"application/json; charset=utf-8\"\n- Request Body:raw json format\n- Request Body:\n\n```json\n{\n    \"title\": \"foo\",\n    \"body\": \"bar\",\n    \"userId\": 1\n}\n```\n\n- Response status code: 201\n- Response header:\"Content-Type\": \"application/json; charset=utf-8\"\n- Response body:\n\n```json\n{\n    \"title\": \"foo\",\n    \"body\": \"bar\",\n    \"userId\": 1,\n    \"id\": 101\n}\n```\n\n#### Writing Test cases\n\n- Open the TestDemo.java file and start writing the test script.\n\n- The example script is as follows. For reference\n\n```java\npackage com.example;\n\nimport org.testng.annotations.Test;\n\nimport static io.restassured.RestAssured.given;\nimport static org.hamcrest.Matchers.equalTo;\n\npublic class TestDemo {\n\n @Test(description = \"Verify that the Get Post API returns correctly\")\n public void verifyGetAPI() {\n\n  // Given\n  given()\n    .baseUri(\"https://jsonplaceholder.typicode.com\")\n             .header(\"Content-Type\", \"application/json\")\n\n  // When\n  .when()\n    .get(\"/posts/1\")\n\n  // Then\n  .then()\n    .statusCode(200)\n    // To verify correct value\n    .body(\"userId\", equalTo(1))\n    .body(\"id\", equalTo(1))\n    .body(\"title\", equalTo(\"sunt aut facere repellat provident occaecati excepturi optio reprehenderit\"))\n    .body(\"body\", equalTo(\"quia et suscipit\\nsuscipit recusandae consequuntur expedita et cum\\nreprehenderit molestiae ut ut quas totam\\nnostrum rerum est autem sunt rem eveniet architecto\"));\n }\n @Test(description = \"Verify that the publish post API returns correctly\")\n public void verifyPostAPI() {\n\n  // Given\n  given()\n    .baseUri(\"https://jsonplaceholder.typicode.com\")\n    .header(\"Content-Type\", \"application/json\")\n\n    // When\n    .when()\n    .body(\"{\\\"title\\\": \\\"foo\\\", \\\"body\\\": \\\"bar\\\", \\\"userId\\\": 1\\n}\")\n    .post(\"/posts\")\n\n    // Then\n    .then()\n    .statusCode(201)\n    // To verify correct value\n    .body(\"userId\", equalTo(1))\n    .body(\"id\", equalTo(101))\n    .body(\"title\", equalTo(\"foo\"))\n    .body(\"body\", equalTo(\"bar\"));\n }\n}\n```\n\n#### Debugging test cases\n\n- Open the Terminal window for this project and run the test script by executing the following command\n\n```bash\ngradle test\n```\n\n#### Viewing Test Reports\n\n##### Command Line Report\n\n![gradle-test-report1](https://cdn.jsdelivr.net/gh/naodeng/blogimg@master/uPic/gradle-report1.png)\n\n##### testng html Report\n\n- Open the project build/reports/tests/test directory.\n- Click on the index.html file to view the test report.\n\n![gradle-test-report2](https://cdn.jsdelivr.net/gh/naodeng/blogimg@master/uPic/gradle-report2.png)\n\n### Maven version\n\nSee the demo project at \u003chttps://github.com/Automation-Test-Starter/RestAssured-maven-demo\u003e\n\n#### Initialize an empty Maven project\n\n```bash\nmvn archetype:generate -DgroupId=com.example -DartifactId=RestAssured-maven-demo -DarchetypeArtifactId=maven-archetype-quickstart -DinteractiveMode=false\n```\n\nInitialization complete: After completing the wizard, Maven will create a new project directory and a basic Maven project structure\n\n#### Configuration pom.xml\n\nAdd the following to the pom.xml file in your project\n\n\u003e You can copy the contents of the pom.xml file in this project. For more information on configuration, please refer to the [official documentation](https://github.com/rest-assured/rest-assured/wiki/GettingStarted#rest-assured).\n\n```xml\n\u003c!-- dependencies config --\u003e\n  \u003cdependencies\u003e\n    \u003c!-- https://mvnrepository.com/artifact/io.rest-assured/rest-assured --\u003e\n    \u003cdependency\u003e\n      \u003cgroupId\u003eio.rest-assured\u003c/groupId\u003e\n      \u003cartifactId\u003erest-assured\u003c/artifactId\u003e\n      \u003cversion\u003e5.3.1\u003c/version\u003e\n      \u003cscope\u003etest\u003c/scope\u003e\n    \u003c/dependency\u003e\n    \u003c!-- https://mvnrepository.com/artifact/org.testng/testng --\u003e\n    \u003cdependency\u003e\n      \u003cgroupId\u003eorg.testng\u003c/groupId\u003e\n      \u003cartifactId\u003etestng\u003c/artifactId\u003e\n      \u003cversion\u003e7.8.0\u003c/version\u003e\n      \u003cscope\u003etest\u003c/scope\u003e\n    \u003c/dependency\u003e\n  \u003c/dependencies\u003e\n  \u003c!-- plugin config --\u003e\n      \u003cplugin\u003e\n        \u003cgroupId\u003eorg.apache.maven.plugins\u003c/groupId\u003e\n        \u003cartifactId\u003emaven-surefire-plugin\u003c/artifactId\u003e\n        \u003cversion\u003e3.2.1\u003c/version\u003e\n        \u003cconfiguration\u003e\n          \u003csuiteXmlFiles\u003e\n            \u003csuiteXmlFile\u003esrc/test/resources/testng.xml\u003c/suiteXmlFile\u003e\n          \u003c/suiteXmlFiles\u003e\n        \u003c/configuration\u003e\n      \u003c/plugin\u003e\n```\n\n#### Configuration testng.xml\n\n- Create a resources directory under the src/test directory to store test configuration files.\n\n- Create a testng.xml file in the resources directory to configure the TestNG test framework.\n\n- For reference, the following is a sample configuration\n\n```xml\n\u003c?xml version=\"1.0\" encoding=\"UTF-8\"?\u003e\n\u003c!DOCTYPE suite SYSTEM \"http://testng.org/testng-1.0.dtd\"\u003e\n\u003csuite name=\"restAssured-gradleTestSuite\"\u003e\n\u003ctest thread-count=\"1\" name=\"Demo\"\u003e\n    \u003cclasses\u003e\n        \u003cclass name=\"com.example.TestDemo\"/\u003e \u003c!-- test case class--\u003e\n    \u003c/classes\u003e\n\u003c/test\u003e \u003c!-- Test --\u003e\n\u003c/suite\u003e \u003c!-- Suite --\u003e\n```\n\n#### initialization maven project directory\n\nThe directory structure can be found in \u003e\u003e [Project structure](#project-structure)\n\nCreate a new test class in the project's test source directory. By default, Gradle usually places the test source code in the src/test/java directory. You can create a package of test classes in that directory and create a new test class in the package\n\nTo create a test class for TestDemo, you can create files with the following structure\n  \n```text\nsrc\n└── test\n    └── java\n        └── com\n            └── example\n                └── TestDemo.java\n```\n\n#### The api used by Demo\n\nreferable to \u003e\u003e [Introduction of demo test API](#introduction-of-demo-test-api)\n\n#### Writing Test cases\n\n- Open the TestDemo.java file and start writing the test script.\n\n- The example script is as follows. For reference\n\n```java\npackage com.example;\n\nimport org.testng.annotations.Test;\n\nimport static io.restassured.RestAssured.given;\nimport static org.hamcrest.Matchers.equalTo;\n\npublic class TestDemo {\n\n @Test(description = \"Verify that the Get Post API returns correctly\")\n public void verifyGetAPI() {\n\n  // Given\n  given()\n    .baseUri(\"https://jsonplaceholder.typicode.com\")\n             .header(\"Content-Type\", \"application/json\")\n\n  // When\n  .when()\n    .get(\"/posts/1\")\n\n  // Then\n  .then()\n    .statusCode(200)\n    // To verify correct value\n    .body(\"userId\", equalTo(1))\n    .body(\"id\", equalTo(1))\n    .body(\"title\", equalTo(\"sunt aut facere repellat provident occaecati excepturi optio reprehenderit\"))\n    .body(\"body\", equalTo(\"quia et suscipit\\nsuscipit recusandae consequuntur expedita et cum\\nreprehenderit molestiae ut ut quas totam\\nnostrum rerum est autem sunt rem eveniet architecto\"));\n }\n @Test(description = \"Verify that the publish post API returns correctly\")\n public void verifyPostAPI() {\n\n  // Given\n  given()\n    .baseUri(\"https://jsonplaceholder.typicode.com\")\n    .header(\"Content-Type\", \"application/json\")\n\n    // When\n    .when()\n    .body(\"{\\\"title\\\": \\\"foo\\\", \\\"body\\\": \\\"bar\\\", \\\"userId\\\": 1\\n}\")\n    .post(\"/posts\")\n\n    // Then\n    .then()\n    .statusCode(201)\n    // To verify correct value\n    .body(\"userId\", equalTo(1))\n    .body(\"id\", equalTo(101))\n    .body(\"title\", equalTo(\"foo\"))\n    .body(\"body\", equalTo(\"bar\"));\n }\n}\n```\n\n#### Debugging test cases\n\n- Open the Terminal window for this project and run the test script by executing the following command\n\n```bash\nmvn test\n```\n\n#### Viewing Test Reports\n\n##### terminal report\n\n![maven-test-report1](https://cdn.jsdelivr.net/gh/naodeng/blogimg@master/uPic/maven-report1.png)\n\n##### testng html report\n\n- Open the project target/surefire-reports directory.\n- Click on the index.html file to view the test report.\n\n![maven-test-report2](https://cdn.jsdelivr.net/gh/naodeng/blogimg@master/uPic/maven-report2.png)\n\n## Advanced Usage\n\n### Verifying Response Data\n\nYou can verify Response status code, Response status line, Response cookies, Response headers, Response content type and Response body.\n\n#### response body assertion\n\n##### json assertion\n  \nAssume that the GET request (to \u003chttp://localhost:8080/lotto\u003e) returns JSON as:\n\n```json\n{\n\"lotto\":{\n \"lottoId\":5,\n \"winning-numbers\":[2,45,34,23,7,5,3],\n \"winners\":[{\n   \"winnerId\":23,\n   \"numbers\":[2,45,34,23,3,5]\n },{\n   \"winnerId\":54,\n   \"numbers\":[52,3,12,11,18,22]\n }]\n}\n}\n```\n\nREST assured makes it easy to make get requests and process response messages.\n\n- Asserts whether the value of lottoId is equal to 5. For example:\n\n```java\nget(\"/lotto\").then().body(\"lotto.lottoId\", equalTo(5));\n```\n\n- Assertion The values for winnerId include 23 and 54. For example:\n\n```java\nget(\"/lotto\").then().body(\"lotto.winners.winnerId\", hasItems(23, 54));\n```\n\n\u003e Note: `equalTo` and `hasItems` are Hamcrest matchers which you should statically import from `org.hamcrest.Matchers`.\n\n##### XML assertion\n\nXML can be verified in a similar way. Imagine that a POST request to \u003chttp://localhost:8080/greetXML\u003e returns:\n\n```xml\n\u003cgreeting\u003e\n   \u003cfirstName\u003e{params(\"firstName\")}\u003c/firstName\u003e\n   \u003clastName\u003e{params(\"lastName\")}\u003c/lastName\u003e\n\u003c/greeting\u003e\n```\n\n- Asserts whether the firstName is returned correctly. For example:\n\n```java\ngiven().\n         parameters(\"firstName\", \"John\", \"lastName\", \"Doe\").\nwhen().\n         post(\"/greetXML\").\nthen().\n         body(\"greeting.firstName\", equalTo(\"John\")).\n```\n\n- Assert that firstname and lastname are returned correctly. For example:\n\n```java\ngiven().\n         parameters(\"firstName\", \"John\", \"lastName\", \"Doe\").\nwhen().\n         post(\"/greetXML\").\nthen().\n         body(\"greeting.firstName\", equalTo(\"John\")).\n         body(\"greeting.lastName\", equalTo(\"Doe\"));\n```\n\n```java\nwith().parameters(\"firstName\", \"John\", \"lastName\", \"Doe\").when().post(\"/greetXML\").then().body(\"greeting.firstName\", equalTo(\"John\"), \"greeting.lastName\", equalTo(\"Doe\"));\n```\n\n#### Cookie assertion\n\n- Asserts whether the value of the cookie is equal to cookieValue. For example:\n\n```java\nget(\"/x\").then().assertThat().cookie(\"cookieName\", \"cookieValue\")\n```\n\n- Asserts whether the value of multiple cookies is equal to the cookieValue at the same time. For example:\n\n```java\nget(\"/x\").then().assertThat().cookies(\"cookieName1\", \"cookieValue1\", \"cookieName2\", \"cookieValue2\")\n```\n\n- Asserts whether the value of the cookie contains a cookieValue. For example:\n\n```java\nget(\"/x\").then().assertThat().cookies(\"cookieName1\", \"cookieValue1\", \"cookieName2\", containsString(\"Value2\"))\n```\n\n#### Status Code Assertion\n\n- Assertion Whether the status code is equal to 200. For example:\n\n```java\nget(\"/x\").then().assertThat().statusCode(200)\n```\n\n- Assertion Whether the status line is something. For example:\n\n```java\nget(\"/x\").then().assertThat().statusLine(\"something\")\n```\n\n- Assertion Whether the status line contains some. For example:\n\n```java\nget(\"/x\").then().assertThat().statusLine(containsString(\"some\"))\n```\n\n#### Header Assertion\n\n- Asserts whether the value of Header is equal to HeaderValue. For example:\n\n```java\nget(\"/x\").then().assertThat().header(\"headerName\", \"headerValue\")\n```\n\n- Asserts whether the value of multiple Headers is equal to HeaderValue at the same time. For example:\n\n```java\nget(\"/x\").then().assertThat().headers(\"headerName1\", \"headerValue1\", \"headerName2\", \"headerValue2\")\n```\n\n- Asserts whether the value of the Header contains a HeaderValue. For example:\n\n```java\nget(\"/x\").then().assertThat().headers(\"headerName1\", \"headerValue1\", \"headerName2\", containsString(\"Value2\"))\n```\n\n- Assert that the \"Content-Length\" of the Header is less than 1000. For example:\n\n\u003e The header can be first converted to int using the mapping function, and then asserted using the \"integer\" matcher before validation with Hamcrest:\n\n```java\nget(\"/something\").then().assertThat().header(\"Content-Length\", Integer::parseInt, lessThan(1000));\n```\n\n#### Content-Type Assertion\n\n- Asserts whether the value of Content-Type is equal to application/json. For example:\n\n```java\nget(\"/x\").then().assertThat().contentType(ContentType.JSON)\n```\n\n#### Full body/content matching Assertion\n\n- Assertion Whether the response body is exactly equal to something. For example:\n\n```java\nget(\"/x\").then().assertThat().body(equalTo(\"something\"))\n```\n\n#### Measuring Response Time\n\n\u003e As of version 2.8.0 REST Assured has support measuring response time. For example:\n\n```java\nlong timeInMs = get(\"/lotto\").time()\n```\n\nor using a specific time unit:\n\n```java\nlong timeInSeconds = get(\"/lotto\").timeIn(SECONDS);\n\n```\n\nwhere 'SECONDS' is just a standard 'TimeUnit'. You can also validate it using the validation DSL:\n\n```java\nwhen().\n      get(\"/lotto\").\nthen().\n      time(lessThan(2000L)); // Milliseconds\n```\n\nor\n\n```java\nwhen().\n      get(\"/lotto\").\nthen().\n      time(lessThan(2L), SECONDS);\n```\n\nNote that you can only referentially correlate these measurements to server request processing times (as response times will include HTTP roundtrips, REST Assured processing times, etc., and cannot be very accurate).\n\n### File Upload\n\nOften we use the multipart form data technique when transferring large amounts of data to the server, such as files.\nrest-assured provides a `multiPart` method to recognize whether this is a file, a binary sequence, an input stream, or uploaded text.\n\n- Upload only one file in the form. For example:\n\n```java\ngiven().\n        multiPart(new File(\"/path/to/file\")).\nwhen().\n        post(\"/upload\");\n```\n\n- Uploading a file in the presence of a control name. For example:\n\n```java\ngiven().\n        multiPart(\"controlName\", new File(\"/path/to/file\")).\nwhen().\n        post(\"/upload\");\n```\n\n- Multiple \"multi-parts\" entities in the same request. For example:\n\n```java\nbyte[] someData = ..\ngiven().\n        multiPart(\"controlName1\", new File(\"/path/to/file\")).\n        multiPart(\"controlName2\", \"my_file_name.txt\", someData).\n        multiPart(\"controlName3\", someJavaObject, \"application/json\").\nwhen().\n        post(\"/upload\");\n```\n\n- MultiPartSpecBuilder use cases. For example:\n\n\u003e For more usage references[MultiPartSpecBuilder](http://static.javadoc.io/io.rest-assured/rest-assured/3.0.1/io/restassured/builder/MultiPartSpecBuilder.html)：\n\n```java\nGreeting greeting = new Greeting();\ngreeting.setFirstName(\"John\");\ngreeting.setLastName(\"Doe\");\n\ngiven().\n        multiPart(new MultiPartSpecBuilder(greeting, ObjectMapperType.JACKSON_2)\n                .fileName(\"greeting.json\")\n                .controlName(\"text\")\n                .mimeType(\"application/vnd.custom+json\").build()).\nwhen().\n        post(\"/multipart/json\").\nthen().\n        statusCode(200);\n```\n\n- MultiPartConfig use cases. For example:\n\n\u003e[MultiPartConfig](http://static.javadoc.io/io.rest-assured/rest-assured/3.0.1/io/restassured/config/MultiPartConfig.html)You can specify the default control name and file name.\n\n```java\ngiven().config(config().multiPartConfig(multiPartConfig().defaultControlName(\"something-else\")))  \n```\n\n\u003e By default, the control name is configured as \"something-else\" instead of \"file\".\n\u003e For more usage references [blog introduction](http://blog.jayway.com/2011/09/15/multipart-form-data-file-uploading-made-simple-with-rest-assured/)\n\n### Logging\n\nWhen we are writing interface test scripts, we may need to print some logs during the test process so that we can view the request and response information of the interface and some other information during the test process.RestAssured provides some methods to print logs.\n\n- RestAssured provides a global logging configuration method that allows you to configure logging before the test starts and then print the logs during the test. This method is applicable to all test cases, but it can only print request and response information, not other information.\n\n- RestAssured also provides a localized log configuration method that prints logs during the test. This method prints request and response information as well as other information.\n\n#### Global logging configuration\n\n##### Steps to add global logging configuration\n\n- Importing logging-related dependency classes\n  \n```java\nimport io.restassured.config.LogConfig;\nimport io.restassured.filter.log.LogDetail;\nimport io.restassured.filter.log.RequestLoggingFilter;\nimport io.restassured.filter.log.ResponseLoggingFilter;\n```\n\n- Adding logging configuration to the setup() method\n\n\u003e Use LogConfig configuration to enable logging of requests and responses, as well as to enable nice output formatting. Enabled logging filters for requests and responses, which will log details of requests and responses.\n\n```java\n// Setting the Global Request and Response Logging Configuration\n        RestAssured.config = RestAssured.config()\n                .logConfig(LogConfig.logConfig()\n                        .enableLoggingOfRequestAndResponseIfValidationFails(LogDetail.ALL)\n                        .enablePrettyPrinting(true));\n```\n\n- Enabled global logging filters in the setup() method\n\n```java\n// Enable global request and response logging filters\n    RestAssured.filters(new RequestLoggingFilter(), new ResponseLoggingFilter());\n```\n\n##### Global Logging Code Example\n\n```java\npackage com.example;\n\nimport io.restassured.RestAssured;\n// Importing logging-related dependency classes\nimport io.restassured.config.LogConfig;\nimport io.restassured.filter.log.LogDetail;\nimport io.restassured.filter.log.RequestLoggingFilter;\nimport io.restassured.filter.log.ResponseLoggingFilter;\nimport org.testng.annotations.BeforeClass;\nimport org.testng.annotations.Test;\n\nimport static io.restassured.RestAssured.given;\nimport static org.hamcrest.Matchers.equalTo;\n\npublic class TestDemo {\n\n    @BeforeClass\n    public void setup() {\n        // Setting the Global Request and Response Logging Configuration\n        RestAssured.config = RestAssured.config()\n                .logConfig(LogConfig.logConfig()\n                        .enableLoggingOfRequestAndResponseIfValidationFails(LogDetail.ALL)\n                        .enablePrettyPrinting(true));\n        // Enable global request and response logging filters\n        RestAssured.filters(new RequestLoggingFilter(), new ResponseLoggingFilter());\n    }\n\n    @Test(description = \"Verify that the Get Post API returns correctly\")\n    public void verifyGetAPI() {\n      // Test cases have been omitted, refer to the demo\n    }\n\n    @Test(description = \"Verify that the publish post API returns correctly\")\n    public void verifyPostAPI() {\n      // Test cases have been omitted, refer to the demo\n    }\n}\n```\n\n##### Viewing Global Log Output\n\n- Open the Terminal window for this project and run the test script by executing the following command\n- Viewing Log Output\n\n![log-sceenshot1](https://cdn.jsdelivr.net/gh/naodeng/blogimg@master/uPic/9Mh9Z8.png)\n\n#### Localized logging configuration\n\nIn RestAssured, you can make localized logging configurations to enable or disable logging for specific test methods or requests without affecting the global configuration.\n\n##### Steps to add Localized logging configuration\n\n- Add logging configuration is enabled in the test method for which you want to print logs\n\n```java\n    @Test(description = \"Verify that the Get Post API returns correctly\")\n    public void verifyGetAPI() {\n\n        // Given\n        given()\n                .log().everything(true)  // Output request-related logs\n                .baseUri(\"https://jsonplaceholder.typicode.com\")\n                .header(\"Content-Type\", \"application/json\")\n\n                // When\n                .when()\n                .get(\"/posts/1\")\n\n                // Then\n                .then()\n                .log().everything(true)  // Output response-related logs\n                .statusCode(200)\n    }\n```\n\n##### Viewing Localized Log Output\n\n- Open the Terminal window for this project and run the test script by executing the following command\n- Viewing Log Output\n\n![report1](https://cdn.jsdelivr.net/gh/naodeng/blogimg@master/uPic/GxZyyG.png)\n\n#### LogConfig Configuration Description\n\nIn Rest-Assured, you can use the `LogConfig` class to configure logging of requests and responses. The `LogConfig` allows you to define the level of logging detail, the output format, the location of the output, and so on. The following are some common `LogConfig` configuration examples:\n\n1. **Enable logging of requests and responses:**\n\n   ```java\n   RestAssured.config = RestAssured.config()\n       .logConfig(LogConfig.logConfig().enableLoggingOfRequestAndResponseIfValidationFails(LogDetail.ALL));;\n   ```\n\n   This will enable logging of requests and responses only if validation fails.\n\n2. **Configure the output level:**\n\n   ``` java\n   RestAssured.config = RestAssured.config()\n       .logConfig(LogConfig.logConfig().enableLoggingOfRequestAndResponseIfValidationFails(LogDetail.HEADERS));;\n   ```\n\n   This will log only the request and response headers.\n\n3. **Configure the location of the output:**\n\n   ```java\n   RestAssured.config = RestAssured.config()\n       .logConfig(LogConfig.logConfig().enableLoggingOfRequestAndResponseIfValidationFails(LogDetail.ALL)\n           .enablePrettyPrinting(true)\n           .defaultStream(FileOutputStream(\"log.txt\"))); ;enablePrettyPrinting(true).enablePrettyPrinting(true)\n   ```\n\n   This outputs the log records to a file named \"log.txt\".\n\n4. **Configure the nice output format:**\n\n   ```java\n   RestAssured.config = RestAssured.config()\n       .logConfig(LogConfig.logConfig().enableLoggingOfRequestAndResponseIfValidationFails(LogDetail.ALL)\n           .enablePrettyPrinting(true));\n   ```\n\n   This will enable nice output formatting and make the logs easier to read.\n\nYou can combine these configuration options according to your specific needs and set it to `RestAssured.config` to configure global request and response logging. This will help log and review requests and responses in RestAssured for debugging and analyzing issues.\n\n#### Request Logging\n\nStarting with version 1.5, REST Assured supports logging request specifications before they are sent to the server using RequestLoggingFilter. Note that HTTP Builder and HTTP Client may add headers other than what is printed in the log. The filter will only log the details specified in the request specification. That is, you cannot consider the details logged by the RequestLoggingFilter to be the details actually sent to the server. In addition, subsequent filters may change the request after logging has occurred. If you need to log what is actually sent over the network, see the HTTP Client Logging documentation or use an external tool such as fiddler.\n\nExamples：\n\n```java\ngiven().log().all() // Log all request specification details including parameters, headers and body\ngiven().log().params() // Log only the parameters of the request\ngiven().log().body() // Log only the request body\ngiven().log().headers()  // Log only the request headers\ngiven().log().cookies()  // Log only the request cookies\ngiven().log().method()  // Log only the request method\ngiven().log().path()  // Log only the request path\n```\n\n#### Response Logging\n\n- Wanting to print only the body of the response, regardless of the status code, you can do the following.\n, for example:\n\n```java\nget(\"/x\").then().log().body()\n```\n\n- The response body will be printed whether or not an error occurs. If only interested in printing the response body when an error occurs, for example:\n\n```java\nget(\"/x\").then().log().ifError()\n```\n\n- Record all details in the response, including status lines, headers, and cookies, for example:\n\n```java\nget(\"/x\").then().log().all()   \n```\n\n- Record only the status line, header, or cookie in the response, for example:\n\n```java\nget(\"/x\").then().log().statusLine()  // Only log the status line\nget(\"/x\").then().log().headers()  // Only log the response headers\nget(\"/x\").then().log().cookies()   // Only log the response cookies\n```\n\n- Configured to log a response only when the status code matches a value. for example:\n\n```java\nget(\"/x\").then().log().ifStatusCodeIsEqualTo(302)   // Only log if the status code is equal to 302\nget(\"/x\").then().log().ifStatusCodeMatches(matcher)   // Only log if the status code matches the supplied Hamcrest matcher\n```\n\n#### Log if validation fails\n\n- Since REST Assured 2.3.1 you can log the request or response only if the validation fails. To log the request do. for example:\n\n```java\ngiven().log().ifValidationFails()\n```\n\n- To log the response. for example:\n\n```java\nthen().log().ifValidationFails()\n```\n\n- It can be enabled for both requests and responses using LogConfig, for example:\n\n```java\ngiven().config(RestAssured.config().logConfig(logConfig().enableLoggingOfRequestAndResponseIfValidationFails(HEADERS)))\n```\n\n\u003e If authentication fails, the log only records the request header.\n\n- Another shortcut to enable request and response logging for all requests if authentication fails, for example:\n  \n```java\nRestAssured.enableLoggingOfRequestAndResponseIfValidationFails();\n```\n\n- Starting with version 4.5.0, you can also use specify the message that will be displayed if the onFailMessage test fails, for example:\n  \n```java\nwhen().\n      get().\nthen().\n      onFailMessage(\"Some specific message\").\n      statusCode(200);\n```\n\n#### Header Blacklist Configuration\n\nStarting with REST Assured 4.2.0, it is possible to blacklist headers so that they do not show up in request or response logs. Instead, the header value will be replaced with [ BLACKLISTED ] . You can enable this feature on a per-header basis using LogConfig, for example:\n  \n```java\ngiven().config(config().logConfig(logConfig().blacklistHeader(\"Accept\")))  \n```\n\n### Filters\n\nIn RestAssured, you can use filters to modify requests and responses. Filters allow you to modify requests and responses at different stages of the request and response process. For example, you can modify the request before the request or the response after the response. You can use filters to add request headers, request parameters, request bodies, response headers, response bodies, and so on.\n\nFilters can be used to implement custom authentication schemes, session management, logging, and so on. To create a filter, you need to implement the io.restassured.filter.Filter interface. To use a filter, you can do the following:\n\n```java\ngiven().filter(new MyFilter())  \n```\n\nThere are a couple of filters provided by REST-Assured that are ready to use:\n\n- `io.restassured.filter.log.RequestLoggingFilter`: A filter that'll print the request specification details.\n- `io.restassured.filter.log.ResponseLoggingFilter`: A filter that'll print the response details if the response matches a given status code.\n- `io.restassured.filter.log.ErrorLoggingFilter`: A filter that'll print the response body if an error occurred (status code is between 400 and 500).\n\n#### Ordered Filters\n\nAs of REST Assured 3.0.2 you can implement the `io.restassured.filter.OrderedFilter` interface if you need to control the filter ordering. Here you implement the getOrder method to return an integer representing the precedence of the filter. A lower value gives higher precedence. The highest precedence you can define is Integer.MIN_VALUE and the lowest precedence is Integer.MAX_VALUE. Filters not implementing `io.restassured.filter.OrderedFilter` will have a default precedence of 1000.\n\n[examples](https://github.com/rest-assured/rest-assured/blob/master/examples/rest-assured-itest-java/src/test/java/io/restassured/itest/java/OrderedFilterITest.java)\n\n#### Response Builder\n\nIf you need to change the Response from a filter you can use the ResponseBuilder to create a new Response based on the original response. For example if you want to change the body of the original response to something else you can do:\n\n```java\nResponse newResponse = new ResponseBuilder().clone(originalResponse).setBody(\"Something\").build();\n```\n\n### CI/CD integration\n\n#### integration github action\n\nUse github action as an example, and other CI tools similarly\n\n##### The Gradle version integration github action\n\nSee the demo at \u003chttps://github.com/Automation-Test-Starter/RestAssured-gradle-demo\u003e\n\n- Create the .github/workflows directory: In your GitHub repository, create a directory called .github/workflows. This will be where the GitHub Actions workflow files will be stored.\n\n- Create a workflow file: Create a YAML-formatted workflow file, such as gradle.yml, in the .github/workflows directory.\n\n- Edit the gradle.yml file: Copy the following into the file\n\n```yaml\nname: Gradle and REST Assured Tests\n\non:\n  push:\n    branches: [ \"main\" ]\n  pull_request:\n    branches: [ \"main\" ]\n\njobs:\n  build:\n    runs-on: ubuntu-latest\n\n    steps:\n      - name: Checkout code\n        uses: actions/checkout@v3\n\n      - name: Setup Java\n        uses: actions/setup-java@v3\n        with:\n          java-version: '11'\n          distribution: 'adopt'\n\n      - name: Build and Run REST Assured Tests with Gradle\n        uses: gradle/gradle-build-action@bd5760595778326ba7f1441bcf7e88b49de61a25 # v2.6.0\n        with:\n          arguments: build\n\n      - name: Archive REST-Assured results\n        uses: actions/upload-artifact@v2\n        with:\n          name: REST-Assured-results\n          path: build/reports/tests/test\n\n      - name: Upload REST-Assured results to GitHub\n        uses: actions/upload-artifact@v2\n        with:\n          name: REST-Assured-results\n          path: build/reports/tests/test\n```\n\n- Commit the code: Add the gradle.yml file to your repository and commit.\n- View test reports: In GitHub, navigate to your repository. Click the Actions tab at the top and then click the Gradle and REST Assured Tests workflow on the left. You should see the workflow running, wait for the execution to complete and you can view the results.\n\n![gradle-test-report3](https://cdn.jsdelivr.net/gh/naodeng/blogimg@master/uPic/gradle-report3.png)\n\n##### The Maven version integration github action\n\nSee the demo at \u003chttps://github.com/Automation-Test-Starter/RestAssured-maven-demo\u003e\n\n- Create the .github/workflows directory: In your GitHub repository, create a directory called .github/workflows. This will be where the GitHub Actions workflow files will be stored.\n\n- Create a workflow file: Create a YAML-formatted workflow file, such as maven.yml, in the .github/workflows directory.\n\n- Edit the maven.yml file: Copy the following into the file\n  \n```yaml\nname: Maven and REST Assured Tests\n\non:\n  push:\n    branches: [ \"main\" ]\n  pull_request:\n    branches: [ \"main\" ]\n\njobs:\n  Run-Rest-Assured-Tests:\n\n    runs-on: ubuntu-latest\n\n    steps:\n    - uses: actions/checkout@v3\n    - name: Set up JDK 17\n      uses: actions/setup-java@v3\n      with:\n        java-version: '17'\n        distribution: 'temurin'\n        cache: maven\n        \n    - name: Build and Run REST Assured Tests with Maven\n      run: mvn test\n      \n    - name: Archive REST-Assured results\n      uses: actions/upload-artifact@v3\n      with:\n        name: REST-Assured-results\n        path: target/surefire-reports\n\n    - name: Upload REST-Assured results to GitHub\n      uses: actions/upload-artifact@v3\n      with:\n        name: REST-Assured-results\n        path: target/surefire-reports\n```\n\n- Commit the code: Add the maven.yml file to the repository and commit.\n- View test reports: In GitHub, navigate to your repository. Click the Actions tab at the top and then click the Maven and REST Assured Tests workflow on the left. You should see the workflow running, wait for the execution to complete and you can view the results.\n\n![maven-test-report3](https://cdn.jsdelivr.net/gh/naodeng/blogimg@master/uPic/maven-report3.png)\n\n### Integrating allure test reports\n\n#### allure Introduction\n\nAllure is an open source testing framework for generating beautiful, interactive test reports. It can be used with a variety of testing frameworks (e.g. JUnit, TestNG, Cucumber, etc.) and a variety of programming languages (e.g. Java, Python, C#, etc.).\n\nAllure test reports have the following features:\n\n- Aesthetically pleasing and interactive: Allure test reports present test results in an aesthetically pleasing and interactive way, including graphs, charts and animations. This makes test reports easier to read and understand.\n- Multi-language support: Allure supports multiple programming languages, so you can write tests in different languages and generate uniform test reports.\nTest case level details: Allure allows you to add detailed information to each test case, including descriptions, categories, labels, attachments, historical data, and more. This information helps provide a more complete picture of the test results.\n- Historical Trend Analysis: Allure supports test historical trend analysis, which allows you to view the historical performance of test cases, identify issues and improve test quality.\n- Categories and Tags: You can add categories and tags to test cases to better organize and categorize test cases. This makes reporting more readable.\n- Attachments and Screenshots: Allure allows you to attach files, screenshots, and other attachments to better document information during testing.\n- Integration: Allure seamlessly integrates with a variety of testing frameworks and build tools (e.g. Maven, Gradle), making it easy to generate reports.\n- Open Source Community Support: Allure is an open source project with an active community that provides extensive documentation and support. This makes it the tool of choice for many automated testing teams.\n\nThe main goal of Allure test reports is to provide a clear, easy-to-read way to present test results to help development teams better understand the status and quality of their tests, quickly identify problems, and take the necessary action. Whether you are a developer, tester, or project manager, Allure test reports provide you with useful information to improve software quality and reliability.\n\nOfficial Website: \u003chttps://docs.qameta.io/allure/\u003e\n\n#### Integration steps\n\n##### The Maven version integration of allure\n\n- Add allure dependency in POM.xml\n\n\u003e Copy the contents of the pom.xml file in this project\n\n```xml\n    \u003c!-- https://mvnrepository.com/artifact/io.qameta.allure/allure-testng --\u003e\n    \u003cdependency\u003e\n      \u003cgroupId\u003eio.qameta.allure\u003c/groupId\u003e\n      \u003cartifactId\u003eallure-testng\u003c/artifactId\u003e\n      \u003cversion\u003e2.24.0\u003c/version\u003e\n    \u003c/dependency\u003e\n    \u003c!-- https://mvnrepository.com/artifact/io.qameta.allure/allure-rest-assured --\u003e\n    \u003cdependency\u003e\n      \u003cgroupId\u003eio.qameta.allure\u003c/groupId\u003e\n      \u003cartifactId\u003eallure-rest-assured\u003c/artifactId\u003e\n      \u003cversion\u003e2.24.0\u003c/version\u003e\n    \u003c/dependency\u003e\n```\n\n- Add allure plugin to POM.xml\n\n```xml\n      \u003cplugin\u003e\n        \u003cgroupId\u003eio.qameta.allure\u003c/groupId\u003e\n        \u003cartifactId\u003eallure-maven\u003c/artifactId\u003e\n        \u003cversion\u003e2.12.0\u003c/version\u003e\n        \u003cconfiguration\u003e\n          \u003cresultsDirectory\u003e../allure-results\u003c/resultsDirectory\u003e\n        \u003c/configuration\u003e\n      \u003c/plugin\u003e\n```\n\n- Create test code for testing the REST API under src/test/java.\n\n\u003e The following is an example of a demo, see the project for details: \u003chttps://github.com/Automation-Test-Starter/RestAssured-maven-demo\u003e.\n\n```java\npackage com.example;\n\nimport io.qameta.allure.*;\nimport io.qameta.allure.restassured.AllureRestAssured;\nimport org.testng.annotations.Test;\nimport static io.restassured.RestAssured.given;\nimport static org.hamcrest.Matchers.equalTo;\n\n@Epic(\"REST API Regression Testing using TestNG\")\n@Feature(\"Verify that the Get and POST API returns correctly\")\npublic class TestDemo {\n\n    @Test(description = \"To get the details of post with id 1\", priority = 1)\n    @Story(\"GET Request with Valid post id\")\n    @Severity(SeverityLevel.NORMAL)\n    @Description(\"Test Description : Verify that the GET API returns correctly\")\n    public void verifyGetAPI() {\n\n        // Given\n        given()\n                .filter(new AllureRestAssured()) // Set up the AllureRestAssured filter to display request and response information in the test report\n                .baseUri(\"https://jsonplaceholder.typicode.com\")\n                .header(\"Content-Type\", \"application/json\")\n\n                // When\n                .when()\n                .get(\"/posts/1\")\n\n                // Then\n                .then()\n                .statusCode(200)\n                // To verify correct value\n                .body(\"userId\", equalTo(1))\n                .body(\"id\", equalTo(1))\n                .body(\"title\", equalTo(\"sunt aut facere repellat provident occaecati excepturi optio reprehenderit\"))\n                .body(\"body\", equalTo(\"quia et suscipit\\nsuscipit recusandae consequuntur expedita et cum\\nreprehenderit molestiae ut ut quas totam\\nnostrum rerum est autem sunt rem eveniet architecto\"));\n    }\n\n    @Test(description = \"To create a new post\", priority = 2)\n    @Story(\"POST Request\")\n    @Severity(SeverityLevel.NORMAL)\n    @Description(\"Test Description : Verify that the post API returns correctly\")\n    public void verifyPostAPI() {        // Given\n        given()\n                .filter(new AllureRestAssured()) // Set up the AllureRestAssured filter to display request and response information in the test report\n                .baseUri(\"https://jsonplaceholder.typicode.com\")\n                .header(\"Content-Type\", \"application/json\")\n\n                // When\n                .when()\n                .body(\"{\\\"title\\\": \\\"foo\\\", \\\"body\\\": \\\"bar\\\", \\\"userId\\\": 1\\n}\")\n                .post(\"/posts\")\n\n                // Then\n                .then()\n                .statusCode(201)\n                // To verify correct value\n                .body(\"userId\", equalTo(1))\n                .body(\"id\", equalTo(101))\n                .body(\"title\", equalTo(\"foo\"))\n                .body(\"body\", equalTo(\"bar\"));\n    }\n\n}\n```\n\n- Run tests and generate Allure reports\n\n```bash\nmvn clean test\n```\n\n\u003e The generated Allure report is in the allure-results file in the project root directory.\n\n- Preview of the Allure Report\n\n```bash\nmvn allure:serve\n```\n\n\u003e Running the command automatically opens a browser to preview the Allure report.\n\n![allure-report](https://cdn.jsdelivr.net/gh/naodeng/blogimg@master/uPic/JsHrOQ.png)\n\n![allure-report1](https://cdn.jsdelivr.net/gh/naodeng/blogimg@master/uPic/ZXgnOD.png)\n\n##### The Gradle version of allure integration\n\n- Add the allure plugin to your build.gradle.\n\n\u003e Copy the contents of the build.gradle file in this project\n\n```groovy\nid(\"io.qameta.allure\") version \"2.11.2\"\n```\n\n- Add allure dependency to build.gradle\n\n\u003e Copy the contents of the build.gradle file in this project\n\n```groovy\n    implementation 'io.qameta.allure:allure-testng:2.24.0' // Add allure report dependency\n    implementation 'io.qameta.allure:allure-rest-assured:2.24.0' // Add allure report dependency\n```\n\n- Create test code for testing the REST API under src/test/java.\n\n\u003e The following is an example of a demo, see the project for details: \u003chttps://github.com/Automation-Test-Starter/RestAssured-gradle-demo\u003e.\n\n```java\npackage com.example;\n\nimport io.qameta.allure.*;\nimport io.qameta.allure.restassured.AllureRestAssured;\nimport org.testng.annotations.Test;\nimport static io.restassured.RestAssured.given;\nimport static org.hamcrest.Matchers.equalTo;\n\n@Epic(\"REST API Regression Testing using TestNG\")\n@Feature(\"Verify that the Get and POST API returns correctly\")\npublic class TestDemo {\n\n    @Test(description = \"To get the details of post with id 1\", priority = 1)\n    @Story(\"GET Request with Valid post id\")\n    @Severity(SeverityLevel.NORMAL)\n    @Description(\"Test Description : Verify that the GET API returns correctly\")\n    public void verifyGetAPI() {\n\n        // Given\n        given()\n                .filter(new AllureRestAssured()) // Set up the AllureRestAssured filter to display request and response information in the test report\n                .baseUri(\"https://jsonplaceholder.typicode.com\")\n                .header(\"Content-Type\", \"application/json\")\n\n                // When\n                .when()\n                .get(\"/posts/1\")\n\n                // Then\n                .then()\n                .statusCode(200)\n                // To verify correct value\n                .body(\"userId\", equalTo(1))\n                .body(\"id\", equalTo(1))\n                .body(\"title\", equalTo(\"sunt aut facere repellat provident occaecati excepturi optio reprehenderit\"))\n                .body(\"body\", equalTo(\"quia et suscipit\\nsuscipit recusandae consequuntur expedita et cum\\nreprehenderit molestiae ut ut quas totam\\nnostrum rerum est autem sunt rem eveniet architecto\"));\n    }\n\n    @Test(description = \"To create a new post\", priority = 2)\n    @Story(\"POST Request\")\n    @Severity(SeverityLevel.NORMAL)\n    @Description(\"Test Description : Verify that the post API returns correctly\")\n    public void verifyPostAPI() {        // Given\n        given()\n                .filter(new AllureRestAssured())                 .filter(new AllureRestAssured()) // Set up the AllureRestAssured filter to display request and response information in the test report\n                .baseUri(\"https://jsonplaceholder.typicode.com\")\n                .header(\"Content-Type\", \"application/json\")\n\n                // When\n                .when()\n                .body(\"{\\\"title\\\": \\\"foo\\\", \\\"body\\\": \\\"bar\\\", \\\"userId\\\": 1\\n}\")\n                .post(\"/posts\")\n\n                // Then\n                .then()\n                .statusCode(201)\n                // To verify correct value\n                .body(\"userId\", equalTo(1))\n                .body(\"id\", equalTo(101))\n                .body(\"title\", equalTo(\"foo\"))\n                .body(\"body\", equalTo(\"bar\"));\n    }\n\n}\n```\n\n- Run the test and generate the Allure report\n\n```bash\ngradle clean test \n``\n\n\u003e The generated Allure report is in the build/allure-results file in the project root directory.\n\n- Preview the Allure report\n\n```bash\ngradle allureServe\n```\n\n\u003e Running the command automatically opens a browser to preview the Allure report.\n\n![allure-report](https://cdn.jsdelivr.net/gh/naodeng/blogimg@master/uPic/JsHrOQ.png)\n\n![allure-report1](https://cdn.jsdelivr.net/gh/naodeng/blogimg@master/uPic/ZXgnOD.png)\n\n## Reference\n\n- Rest assured official documentation: \u003chttps://rest-assured.io/\u003e\n\n- Rest assured official github:\u003chttps://github.com/rest-assured/rest-assured\u003e\n\n- Rest assured official docs in Chinese: \u003chttps://github.com/RookieTester/rest-assured-doc\u003e\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fautomation-test-starter%2Frestassured-api-test-starter","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fautomation-test-starter%2Frestassured-api-test-starter","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fautomation-test-starter%2Frestassured-api-test-starter/lists"}