This is a simple example of how to run tests in multiple containers using Docker and Docker Compose. and generate a common allure report.
- Dockerfile: This file contains the Dockerfile configuration, which uses maven-jdk image. It also copies the
pom.xml
,src
folder, and XML files. - docker-compose.yml: The Docker Compose file defines three services:
- The first two services are used to run tests in two different containers.
- The third service is responsible for generating the common allure report.
- pom.xml: This file contains the project dependencies.
- src/test: This directory contains the test files.
- *.xml: Multiple XML files are created to specify the tests to be run in each container.
- Clone the repository
- Give execute permission to the
docker-compose-entrypoint.sh
file
chmod +x docker-compose-entrypoint.sh
- Run the following command to run the tests in multiple containers and generate a common allure report.
- To run specific groups, use the following command
./docker-compose-entrypoint.sh <-Dgroups={group_name}> <-Dgroups={group_name}>
Example:
./docker-compose-entrypoint.sh -Dgroups=container1 -Dgroups=container2
- To run specific xml files, use the following command
./docker-compose-entrypoint.sh <-Dsurefire.suiteXmlFiles={xml_file_name}> <-Dsurefire.suiteXmlFiles={xml_file_name}>
Example:
./docker-compose-entrypoint.sh -Dsurefire.suiteXmlFiles=container1.xml -Dsurefire.suiteXmlFiles=container2.xml
After running the tests, to view the combined allure report.
- Go to your chrome browser and type the following url
http://localhost:5050/allure-docker-service/latest-report
- Open the terminal
- Get the container id of the container in which you want to run the tests
docker ps
- Run the following command to run the tests in the container
docker exec -it <container_id> /bin/bash
- Run the following command to run the tests in the container
mvn test -Dgroups={group_name}
- Now refresh the below link you will be able to see the latest test along with the previous run in the report
http://localhost:5050/allure-docker-service/latest-report