Skip to content

Latest commit

 

History

21 Commits

Folders and files

NameName
Last commit message
Last commit date
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Calculator - TestNG Maven Project

This project demonstrates a Java-based Calculator application with automated test cases using TestNG and Maven. It showcases Maven project structure, unit and integration testing, and code coverage reporting using the Surefire, Failsafe, and JaCoCo plugins. It showcases how to structure a Maven project, execute tests, and generate reports using the Maven Surefire Plugin.

Tech Stack

  • Java
  • Maven
  • TestNG
  • Maven Plugins: Surefire, Failsafe, JaCoCo

Tools

  • IntelliJ IDEA (IDE)
  • Git & GitHub (version control)

Features

  • Basic calculator operations (Add, Subtract, Multiply, Divide)
  • Automated test execution using TestNG
  • Maven-based project structure
  • Test execution using Maven lifecycle
  • Unit test execution and HTML reports via Maven Surefire Plugin
  • Integration test execution via Maven Failsafe Plugin
  • Code coverage reports via JaCoCo Plugin

How to Run test

Prerequisites

  • Java 11+ installed
  • Maven installed and configured
  • Git (to clone the repo)

Clone and navigate

git clone https://github.com/AthiraThulasi/Calculator-TestNG-Maven.git
cd Calculator-TestNG-Maven

Run unit tests (Surefire)

mvn clean test

This command:

  • Removes old build files for a fresh start
  • Compiles the project
  • Runs TestNG unit tests
  • Generates reports at target/surefire-reports/

Generate code coverage report (JaCoCo)

mvn clean verify

After the build, open: target/site/jacoco/index.html

Test Reports

Test execution and coverage reports are generated by the configured Maven plugins.

Surefire (Unit Tests)

Path: target/surefire-reports/ Includes:

  • HTML report
  • XML results
  • Execution summary

Failsafe (Integration Tests)

Path: target/failsafe-reports/ Includes:

  • HTML report
  • XML results
  • Integration test summary

JaCoCo (Code Coverage)

Path: target/site/jacoco/ Includes:

  • index.html- interactive coverage report
  • Line, branch, and method coverage breakdowns

Key Takeaways:

  • Importance of standard Maven project structure for scalability and maintainability
  • Maven lifecycle phases (validate → compile → test → package → install → deploy)
  • Role of pom.xml as the central configuration file managing dependencies and build lifecycle
  • Integration of TestNG with Maven for automated test execution
  • How Maven Surefire Plugin executes TestNG tests and generates reports
  • Difference between Surefire (unit tests) and Failsafe (integration tests), including the *IT.java naming convention and why Failsafe runs in the integration-test and verify phases
  • How JaCoCo measures code coverage (line, branch, method) and how coverage reports help identify untested code paths
  • Version control using Git and pushing code to GitHub using terminal commands

Test Automation Best Practices Followed

  • Descriptive Test Naming — Test methods follow methodName_condition_expectedResult (e.g., add_TwoIntegers_returnSum)
  • No Loops in Test Cases — Each test validates a single scenario for simplicity and readability
  • No Exception Handling in Tests — Exceptions fail tests naturally, surfacing real issues
  • Avoid Code Duplication — Common objects are declared as instance variables rather than recreated per test
  • No Input/Output Operations — Tests avoid external files or user input for reliability

Test Execution Result

This report shows the successful execution of TestNG test cases with all tests passing.

Surefire Report

About

A Maven-based automation project for Calculator application using TestNG, demonstrating test execution, reporting, and build management

Resources

Stars

0 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages