An automation testing framework for REST API using TestNG, RestAssured, Data-Driven, ExtentReport.
- reports: where the generated reports located.
- execution: contains execution xml file to run the test (follow TestNG framework).
- resources: contains schema file for schema validation.
- config: contains config file for url, port, extent report config, ...
- suites: contains test cases groups by suites.
- TestEntity: contains test object including test suite, test case, test step.
- TestExecution: functions and methods to execute the test.
- Utils: some additional functions written here.
-
Execution xml file is used to trigger the test and specify the json test case data to run.
-
The framework read and get the test case data from json file, map it into test suite (a set of test cases).
-
Each test case will be executed with corresponding method (GOT, POST, PUT, DELTE), request headers, body.
-
The response will be stored and validated with the expected status code, values or schemas.
-
The test result of test cases is stored and written into test report.
-
The whole process of execute test case is iterated until no test cases left.
-
The whole process of execute test suite is iterated until no test suites left (since an execution xml file may specify more than 1 test data json file).
-
The total result is written into report.
-
Fully operational testing process that implemeneted Data-Driven Framework using json-format test cases as data source.
-
Easy to learn, easy to understand, easy to create json test cases yourself with well-structured format.
-
Built-in ExtentReport with best customized output reports for REST API testing.
-
Implemented Hamcrest Matchers for validation of API response's value. For example: greater than, less than, has key, has item, not, is, equal to, every item, contains, ...
-
Implemented RestAssured for comparing the actual response schema property with expected schema and making fully supported API request with content type, headers, body, ...
-
Test cases executed with run-time variables or pre-defined variables. For example: "datetime" : @var->TODAY@, when the test case is executed, the value will be repaced as "datetime": "2020-02-20".
-
Extended from TestNG for multi-thread test execution, parallel testing with running multiple set of test suite at the same time.
-
Test execution from command line, which is super beneficial for CI/CD pipeline process.
Create a new json file with structure as below description, place it under suites folder:
- suiteName: Name of the suite.
- suiteDescription: Description of the suite.
- testId: ID of the test case.
- testName: Name of the test case.
- testDescription: Description of the test case.
- testObjective: Objective of the test case.
- method: Method of API request (GET/POST/PUT/DELETE).
- name: Name of the test step.
- url: URL to the endpoints (only specify the route since the base URL had been specified).
- request: The request section, may contain path, query parameters, body request, headers.
- response: The expected result or validation.
- statusCode: The expected status code of return response.
- schemaPath: The path to the expected schema that will be used to compare with actual response schema.
- body: Hamcrest Matchers method for validation.
There 3 type of validation of the response: status code, schema and body value.
- statusCode: The expected status code of the response. Ex: 200, 201, 404, 500, ...
- schemaPath: The path to the schema file. The schema file is located in resources/schemas folder.
- body: Based on Hamcrest Matcher functions.
Ex1: To compare value of field name is equal to Tester, the below script is used:
"name": {"is": "Tester"}
where "is" is one of the functions of Hamcrest Matchers.
Ex2: To compare value of field count is greater than 5, the below script is used:
"count": {"greaterThan": 5}
where "greaterThan" is one of the functions of Hamcrest Matchers.
More Hamcrest Matchers functions can be built by coding yourself. Some available built-in matchers in project:
1. equalTo: Compare if logically equal to expected value.
2. equalToIgnoringCase: Compare if equal to expected value ignoring the case of characters.
3. everyItem: Compare every item of response.
4. greaterThan: Compare if greater than the expected value.
5. greaterThanOrEqual: Compare if greater than or equal the expected value.
6. lessThan: Compare if less than the expected value.
7. lessThanOrEqual: Compare if less than or equal the expected value.
8. hasItem: Compare if the response has the expected item.
9. not: Invert the logic.
Variable is generated at runtime. The structure is @var-> @.
Here is the example of using TODAY value, which can prevent causing the error of creating duplicate emails:
Some available built-in variables in project:
1. TODAY: Today string.
2. NOW_HH:mm: Now string format.
4. NOW+1_HH:mm: Current hour +1 format.
4. TODAY_yyyy-MM-dd: Today string with yy-MM-dd format.
5. YESTERDAY_yyyy-MM-dd: Yesterday string with yy-MM-dd format.
6. TOMORROW_yyyy-MM-dd: Tomorrow string with yy-MM-dd format.
7. NEXTMONTH_yyyy-MM-dd: Next month date string with yy-MM-dd format.
8. RANDOM_alphanumeric_5: Random string of 5 alphanumeric.
9. RANDOM_numeric_5: Random string of 5 numeric.
10. RANDOM_alphabetic_5: Random string of 5 alphabet.
Test execution methodology is powered by TestNG, it requires the xml execution file, which is under execution folder.
Specify the test case json file that has been created under suite folder. Run the xml file for running the test. Use Ctrl + Shift + F10 in the case of IntelliJ IDEA.
Powered by Maven plugins.
Format: mvn clean test -DtestSuiteName="path to execution file"
-
Extendability for variety of action-based type via action factory class.
-
Executing script inside a test step.
-
Combinations of mandatory and optional query parameters to generate set of combined test cases.
-
Data-driven test cases with parameterized data table.
-
Skip option for failed test steps, the next step is ongoing executed.
-
Store process variables when executing the test cases at runtime.
-
Load multiple json data files with one test class.
-
Run the specific test cases only.
Copyright 2020 Tuyen Nguyen
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.