Test Automation as Java Application

Pavel Klindziuk
Dandelion Tutorials
2 min readDec 22, 2022
Geek and Poke

A New World View
Currently we have a few ways to run our integration and e2e tests using Maven or Gradle tools. But after all, nothing prevents us from considering our tests as a Java application, using all the benefits and the flexible ways to customize them.
Containerization is one of the biggest benefits, because containers have become the standard for Java applications. Containerization brings a lot of benefits like a consistent environment, repeatable builds and easy deployment patterns.
Running test scripts in containers can allow use not only in “regular” pipelines, but also allows the execution of test scripts in some Cloud Native CI/CD pipelines and frameworks such as Tekton and etc.

What is Java Application?
A Java application is a program written in Java that is executed stand-alone either in a client or a server.

What is Containerization?
Containerization is a type of virtualization in which all the components of an application are bundled into a single container image and can be run in isolated user space on the same shared operating system

Application

So, in this tutorial we will create simple Test Automation Framework based on TestNG, package it into .jar file and containerize it using Jib Gradle plugin.

Prerequisites

  • Install JDK11 or higher
  • Install Docker
  • Make a cup of coffee

Application setup

  • Initialize new Gradle project
  • Add Jib plugin to build.gradle.
  • Configure jar build
  • Configure Jib parameters

Test Automation Framework setup

  • Add TestNGSuiteRunner class with main() method
  • Add some simple test scripts

Run test scripts via jar

  • Generate executable jar via command
    ./gradlew clean build
  • Run test scripts as java application via command
    java -jar build/libs/taas-1.0-SNAPSHOT.jar
  • Verify results

Run test scripts via docker container

  • Run command and let the Jib do the trick
    ./gradlew jibDockerBuild
  • Run container with test java application via command
    docker run klindziuk/taaja
  • Verify results

Test Results Observation

Since test results are inside docker container we need to find a way to observe them. Allure Docker Service will help us with that:

  • Mount appropriate volumes:
    - ${PWD}/build/allure-results:/app/allure-results
    - ${PWD}/build/allure-reports:/app/allure-reports
  • For a more convenient launch, let’s use docker-compose file
  • Start services via command and wait for build finished
    docker-compose -f docker-compose.yml up
  • Open http://localhost:5050/latest-report and verify results

Viola!

Source code can be found on GitHub:

--

--