Prajwalgn-07 / Tests-in-containers

Run tests in containers

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Run tests in multiple containers

docker-container

This is a simple example of how to run tests in multiple containers using Docker and Docker Compose. and generate a common allure report.

File structure

File structure

Overview

  1. Dockerfile: This file contains the Dockerfile configuration, which uses maven-jdk image. It also copies the pom.xml, src folder, and XML files.
  2. 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.
  3. pom.xml: This file contains the project dependencies.
  4. src/test: This directory contains the test files.
  5. *.xml: Multiple XML files are created to specify the tests to be run in each container.

How to run

  1. Clone the repository
  2. Give execute permission to the docker-compose-entrypoint.sh file
chmod +x docker-compose-entrypoint.sh
  1. 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

How to view the report

After running the tests, to view the combined allure report.

  1. Go to your chrome browser and type the following url
http://localhost:5050/allure-docker-service/latest-report

After running tests in multiple continers, if u want to run the tests in only one of the container

  1. Open the terminal
  2. Get the container id of the container in which you want to run the tests
docker ps
  1. Run the following command to run the tests in the container
docker exec -it <container_id> /bin/bash
  1. Run the following command to run the tests in the container
mvn  test -Dgroups={group_name}
  1. 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

Resources

About

Run tests in containers


Languages

Language:Java 70.0%Language:Shell 18.8%Language:Dockerfile 11.2%