|
1 | | -# Test Automation Project |
| 1 | +# Test Automation Framework - API Automation with REST Assured, Spring Boot and JUnit 5 |
2 | 2 |
|
3 | | -This is a test automation project for JUPITER platform (demo version). |
| 3 | +## Overview |
4 | 4 |
|
5 | | -## Project components |
| 5 | +This is a robust and scalable test automation framework built with modern **Java** technologies |
| 6 | +**for testing RESTful APIs**. The framework leverages a variety of open-source libraries and tools to create |
| 7 | +an efficient, reliable, and easily extensible solution for automated API testing. |
6 | 8 |
|
7 | | -Given test automation project is built with next key frameworks and technologies: |
| 9 | +## Key Technologies and Libraries |
8 | 10 |
|
9 | | -- [Java 21](https://openjdk.org/projects/jdk/21/); |
10 | | -- [Maven 3.9.9](https://maven.apache.org/); |
11 | | -- [Spring](https://spring.io/) for bean lifecycle management, dependency injection and configuration properties; |
12 | | -- [REST Assured](https://rest-assured.io/) REST API client library; |
13 | | -- [Project Lombok](https://projectlombok.org/) |
14 | | -- [JUnit 5](https://junit.org/junit5/) testing framework |
15 | | -- [AssertJ](https://assertj.github.io/doc/) for assertions; |
16 | | -- [Allure](https://docs.qameta.io/allure/) reporting framework |
17 | | -- [Jackson](https://github.com/FasterXML/jackson) for serialization/deserialization |
| 11 | +- [Java 21](https://openjdk.org/projects/jdk/21/): A modern version of Java that offers enhanced performance, security, |
| 12 | + and new features. |
| 13 | +- [Maven 3.9.9](https://maven.apache.org/): The build automation tool to manage dependencies and build processes. |
| 14 | +- [Spring Boot](https://spring.io/projects/spring-boot/): For dependency injection (DI) and easy management of |
| 15 | + configuration properties. |
| 16 | +- [REST Assured](https://rest-assured.io/): A powerful REST API client library used for sending HTTP requests and |
| 17 | + validating responses. |
| 18 | +- [JUnit 5](https://junit.org/junit5/): The testing framework for writing and running tests. It supports both |
| 19 | + traditional and parameterized tests. |
| 20 | +- [Project Lombok](https://projectlombok.org/): To reduce boilerplate code, such as getters, setters, and constructors. |
| 21 | +- [AssertJ](https://assertj.github.io/doc/): A fluent assertion library used for clearer and more readable assertions in |
| 22 | + tests. |
| 23 | +- [Jackson](https://github.com/FasterXML/jackson): For JSON serialization and deserialization, making it easier to |
| 24 | + handle JSON data. |
| 25 | +- [Log4j2](https://logging.apache.org/log4j/): A powerful and flexible logging framework used to log detailed |
| 26 | + information during test execution, enabling efficient troubleshooting and analysis. |
| 27 | +- [Allure Report](https://docs.qameta.io/allure/): A framework to generate interactive and visual test reports. |
18 | 28 |
|
19 | | -## Installation guide |
| 29 | +## Testing Services |
20 | 30 |
|
21 | | -Project usage requires next to be installed: |
| 31 | +The framework is designed to test REST APIs from different services: |
22 | 32 |
|
23 | | -- Java 21; |
24 | | -- Git; |
25 | | -- [Allure CLI](https://www.npmjs.com/package/allure-commandline) |
| 33 | +- [Reqres API](https://reqres.in/): A mock API for testing user registration and login. |
| 34 | +- [Travelpayouts API](https://travelpayouts.github.io/slate/): An API for accessing data related to travel. |
26 | 35 |
|
27 | | -## Clone the project from GitHub: |
| 36 | +## Key Features |
| 37 | + |
| 38 | +- **API and Data-Driven Testing:** The framework includes both traditional API tests and parameterized tests (using |
| 39 | + `@ParameterizedTest` in JUnit 5) to demonstrate data-driven testing approaches. |
| 40 | +- **Parallel Test Execution:** Tests can be executed in parallel to reduce test suite runtime. |
| 41 | +- **Logging:** Utilizes `@Log4j2` for detailed logging during test execution, with configuration managed through the |
| 42 | + `log4j2.xml` file. |
| 43 | +- **Allure Reporting:** Generates detailed test execution reports to visualize results. Allure reports are available |
| 44 | + online at **[Allure Report](https://alex-sviatenko.github.io/rest-assured-test-automation/)**, providing |
| 45 | + insights into testing results and trends. |
| 46 | + |
| 47 | +## Getting Started |
| 48 | + |
| 49 | +### Prerequisites |
| 50 | + |
| 51 | +- JDK 21 or higher. |
| 52 | +- Git |
| 53 | +- Maven for build and dependency management. |
| 54 | +- [Allure Commandline](https://www.npmjs.com/package/allure-commandline/) |
| 55 | + |
| 56 | +### Clone repository |
| 57 | + |
| 58 | +1. [Fork](https://github.com/alex-sviatenko/rest-assured-test-automation/fork) the repository. |
| 59 | +2. Clone the repository and navigate to the project |
28 | 60 |
|
29 | 61 | ``` |
30 | | -$ cd project_repo |
31 | | -$ git clone git@github.com:alex-sviatenko/jupiter-test-automation.git |
| 62 | +$ git clone https://github.com/[your_username]/rest-assured-test-automation.git |
| 63 | +$ cd rest-assured-test-automation |
32 | 64 | ``` |
33 | 65 |
|
34 | | -# Running Tests |
| 66 | +## Running Tests |
35 | 67 |
|
36 | | -Example: |
| 68 | +To run the tests, simply execute: |
37 | 69 |
|
38 | 70 | ```shell |
39 | 71 | ./mvnw clean test |
40 | 72 | ``` |
41 | | -## Parallel Test Execution |
42 | 73 |
|
43 | | - To run test in parallel mode use Junit runner with following properties: |
44 | | -> systemProperty "junit.jupiter.execution.parallel.enabled", true |
45 | | -> systemProperty "junit.jupiter.execution.parallel.mode.default", "concurrent" |
46 | | -> systemProperty "junit.jupiter.execution.parallel.mode.classes.default", "concurrent" |
47 | | -> systemProperty "junit.jupiter.execution.parallel.config.strategy", "fixed" |
48 | | -> systemProperty "junit.jupiter.execution.parallel.config.fixed.parallelism", 3 |
| 74 | +For parallel execution, ensure the appropriate configurations for JUnit are set in the `junit-platform.properties` file. |
49 | 75 |
|
50 | | -## Retry Flaky Tests |
| 76 | +## Parallel Test Execution with JUnit 5 |
51 | 77 |
|
52 | | -You may re-run flaky tests. Set the **rerunFailingTestsCount** property to be a value larger than 0. Tests will be run until they pass or the number of reruns has been exhausted. |
53 | | -```shell |
54 | | -./mvnw clean test -Dsurefire.rerunFailingTestsCount=2 |
| 78 | +To optimize test suite runtime, tests can be executed in parallel. This reduces the overall execution time, especially |
| 79 | +when dealing with a large number of tests. JUnit 5 supports parallel execution of tests out of the box with simple |
| 80 | +configuration settings. |
| 81 | + |
| 82 | +To enable parallel test execution, you need to add the following properties to the JUnit runner configuration. These |
| 83 | +settings control how tests are executed in parallel and can be adjusted based on your project needs. |
| 84 | + |
| 85 | +```properties |
| 86 | +junit.jupiter.execution.parallel.enabled=true |
| 87 | +junit.jupiter.execution.parallel.mode.default=concurrent |
| 88 | +junit.jupiter.execution.parallel.config.strategy=fixed |
| 89 | +junit.jupiter.execution.parallel.config.fixed.parallelism=5 |
55 | 90 | ``` |
56 | | -You may add the configuration directly to your pom.xml file under the Surefire plugin configuration. This way, you won't need to pass the **-Dsurefire.rerunFailingTestsCount** property on the command line. |
| 91 | + |
| 92 | +Let’s break down what each of these settings means: |
| 93 | + |
| 94 | +1. `junit.jupiter.execution.parallel.enabled = true` |
| 95 | + |
| 96 | +This setting enables the parallel execution feature of JUnit 5. By default, parallel execution is disabled, so you |
| 97 | +need to explicitly set this property to true to activate it. |
| 98 | + |
| 99 | +2. `junit.jupiter.execution.parallel.mode.default = concurrent` |
| 100 | + |
| 101 | +This setting defines the default mode for test execution. |
| 102 | + |
| 103 | +- `concurrent:` Tests will be executed concurrently (in parallel) by JUnit 5. This is the mode you'll want to use when |
| 104 | + aiming to reduce runtime and fully utilize parallelism. |
| 105 | +- Other options include `same_thread` (which runs all tests in the same thread) and `dynamic` (which adapts to parallel |
| 106 | + execution depending on the situation). |
| 107 | + |
| 108 | +3. `junit.jupiter.execution.parallel.config.strategy = fixed` |
| 109 | + |
| 110 | +This setting determines how the parallel execution strategy is configured. |
| 111 | + |
| 112 | +- `fixed:` This option allows you to specify a fixed level of parallelism, i.e., the number of test threads that should |
| 113 | + run concurrently. You define this value through the next setting. |
| 114 | +- Another option, `dynamic`, adjusts the parallelism dynamically based on the system's available resources, but a fixed |
| 115 | + approach provides more predictable and stable execution. |
| 116 | + |
| 117 | +4. `junit.jupiter.execution.parallel.config.fixed.parallelism = 5` |
| 118 | + |
| 119 | +This setting specifies the fixed number of threads (parallelism) JUnit will use to run tests concurrently. In this |
| 120 | +case, it is set to 5, meaning a maximum of `5` tests will run simultaneously. You can adjust this number based on the |
| 121 | +available resources on your machine or CI server to find the optimal level of parallelism. |
| 122 | + |
| 123 | +## Flaky Test Retry Mechanism |
| 124 | + |
| 125 | +The framework includes a **Retry Flaky Tests** mechanism, enabling automatic re-runs for failing tests to ensure |
| 126 | +stability |
| 127 | +in case of intermittent failures. This can be configured with: |
| 128 | + |
| 129 | +- Command-line option: |
| 130 | + |
| 131 | +```shell |
| 132 | +./mvnw clean test -Dsurefire.rerunFailingTestsCount=2 |
57 | 133 | ``` |
| 134 | + |
| 135 | +- Maven `pom.xml` configuration: |
| 136 | + |
| 137 | +```xml |
58 | 138 | <plugin> |
59 | | - <groupId>org.apache.maven.plugins</groupId> |
60 | | - <artifactId>maven-surefire-plugin</artifactId> |
61 | | - <version>${maven.surefire.plugin}</version> |
62 | | - <configuration> |
63 | | - <rerunFailingTestsCount>2</rerunFailingTestsCount> |
64 | | - </configuration> |
| 139 | + <groupId>org.apache.maven.plugins</groupId> |
| 140 | + <artifactId>maven-surefire-plugin</artifactId> |
| 141 | + <version>${maven.surefire.plugin}</version> |
| 142 | + <configuration> |
| 143 | + <rerunFailingTestsCount>2</rerunFailingTestsCount> |
| 144 | + </configuration> |
65 | 145 | </plugin> |
66 | 146 | ``` |
67 | | -This will configure the Surefire plugin to automatically rerun failing tests 2 times without needing to pass the property via the command line. |
68 | | -If **rerunFailingTestsCount** is set to a value smaller than or equal to 0, then it will be ignored. |
69 | 147 |
|
| 148 | +This setup ensures that failing tests are re-run up to `2` times (or any other specified value) before they are marked |
| 149 | +as failed. If `rerunFailingTestsCount` is set to a value smaller than or equal to 0, then it will be ignored. |
70 | 150 |
|
71 | | -# Creating Allure report |
| 151 | +## Allure Report |
72 | 152 |
|
73 | | -To create allure report execute command: |
74 | | -1. If you need to save the report for future reference or for sharing it with colleagues. It will generate test results and saves an HTML report into the **allure-report** directory |
75 | | -``` |
76 | | -$ allure generate ./target/allure-results/ --clean |
77 | | -$ allure open |
78 | | -``` |
| 153 | +The reports can be generated and opened with: |
79 | 154 |
|
80 | | -2. If you need to create the same report as **allure generate**, but put it into a temporary directory and start a local web server configured to show this directory's contents. The command then automatically opens the main page of the report in a web browser. |
| 155 | +- Option 1: |
81 | 156 |
|
| 157 | +```shell |
| 158 | + allure generate ./target/allure-results/ --clean |
| 159 | + allure open |
82 | 160 | ``` |
83 | | -$ allure serve ./target/allure-results/ |
| 161 | + |
| 162 | +`--clean` - clean Allure report directory before generating a new one. |
| 163 | + |
| 164 | +- Option 2: |
| 165 | + |
| 166 | +```shell |
| 167 | + allure serve ./target/allure-results/ |
84 | 168 | ``` |
0 commit comments