# pitest/pitest-testng-plugin architecture

> Architecture diagram of the GitHub repository pitest/pitest-testng-plugin, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2025-04-02). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/pitest/pitest-testng-plugin
- Repository: https://github.com/pitest/pitest-testng-plugin

## Overview

##### Project Type and Purpose
- This is an open-source Java plugin specifically designed to extend pitest with TestNG support.
- Its primary goal is to integrate TestNG test execution within the mutation testing workflow provided by pitest.
- The README clarifies that the plugin must be placed on the pitest tool's classpath, and it presents details regarding its Maven configuration and version compatibility.

##### Analyzing the File Structure
- Top-Level Directories:
- .github: Contains CI/CD configuration for automated testing and releases (ci.yml, release.yml, snapshot.yml).
- src/main: Holds the main source code, particularly under the package org.pitest.testng; these files implement the actual plugin functionalities.
- src/main/resources: Contains META-INF/services which registers the plugin (org.pitest.testapi.TestPluginFactory) as a service, enabling pitest to discover it.
- src/test: Includes tests for validating the plugin’s behavior, with test classes that simulate various TestNG scenarios.
- pom.xml: This Maven build file controls project dependencies, build lifecycle, and configuration, indicating that Maven is the build and dependency management tool.

##### Main Components
a. Plugin Core (in src/main/java/org/pitest/testng):
- TestNGAdapter, TestNGConfiguration, TestNGPlugin, TestNGTestUnit, and TestNGTestUnitFinder: these classes form the core logic for adapting TestNG tests to pitest framework.
- FailureTracker: likely responsible for capturing or reporting test failures.

b. Service Provider Interface (in src/main/resources/META-INF/services):
- The service registration file (org.pitest.testapi.TestPluginFactory) denotes the plugin’s entry point for pitest to load the extension.

c. Testing Components (in src/test):
- Contains various test classes (e.g., AbstractTestNGClass, Fails, Passes) to validate plugin functionality. It’s useful to feature these as a separate testing module in the design.

d. Build & Continuous Integration:
- pom.xml: Represents the build configuration.
- .github/workflows (ci.yml, release.yml, snapshot.yml): Represent the CI/CD pipelines that run tests, create releases, and manage snapshots, ensuring a continuous deployment process.

##### Relationships and Interactions
- The plugin integrates with pitest via the TestNGPlugin and related classes:
- The TestNGAdapter connects TestNG test cases to pitest’s mutation testing flow.
- TestNGConfiguration is used to configure how TestNG is invoked and interacted with.
- Service registration in META-INF/services informs pitest about the plugin, ensuring the correct loading of the TestNG adapter.
- Maven is used to package the plugin and manage its dependencies.
- CI/CD workflows ensure that tests (found in src/test) are executed on commits/pull requests, and releases are automatically managed.

##### Architectural Patterns & Design Principles
- Service Provider Interface (SPI): The use of META-INF/services indicates a plugin-design pattern where the core app (pitest) discovers and interacts with plugins dynamically.
- Separation of Concerns: Core plugin logic, testing logic, and build/CI configuration are separated into distinct directories and modules.
- Dependency Injection/Modular Design: The plugin is designed to be added to the classpath of pitest (not the project being tested), keeping a clear boundary between the mutated application and the mutation tool.

## Diagram (Mermaid)

```mermaid
flowchart TB
    %% Maven Build System and CI/CD Pipelines
    CI["CI/CD Pipelines<br/>(.github/workflows)"]:::ci
    Maven["Maven Build System<br/>(pom.xml)"]:::maven
    CI -->|"triggers"| Maven

    %% Plugin Core Subgraph
    subgraph "Pitest-TestNG Plugin Core"
        Core["Pitest-TestNG Plugin Core"]:::plugincore
        Adapter["TestNGAdapter"]:::plugincore
        Config["TestNGConfiguration"]:::plugincore
        Plugin["TestNGPlugin"]:::plugincore
        TestUnit["TestNGTestUnit"]:::plugincore
        Finder["TestNGTestUnitFinder"]:::plugincore
        Failure["FailureTracker"]:::plugincore
        Core -->|"calls"| Adapter
        Adapter -->|"configures"| Config
        Config -->|"initializes"| Plugin
        Plugin -->|"executes"| TestUnit
        TestUnit -->|"locates"| Finder
        Finder -->|"reports"| Failure
    end

    %% Service Registration Subgraph
    subgraph "Service Registration (SPI)"
        ServiceReg["Service Registration<br/>(org.pitest.testapi.TestPluginFactory)"]:::service
    end

    %% Test Suite
    TestSuite["Test Suite<br/>(src/test)"]:::tests

    %% External Pitest Tool
    External["Pitest Tool (External)"]:::external

    %% Connections between components
    Maven -->|"builds"| Core
    Maven -->|"registers"| ServiceReg
    Maven -->|"runs"| TestSuite

    TestSuite -->|"validates"| Core

    External -->|"discovers via SPI"| ServiceReg
    ServiceReg -->|"loads"| Core
    External -->|"invokes"| Core

    %% Click Events
    click Core "https://github.com/pitest/pitest-testng-plugin/tree/main/src/main/java/org/pitest/testng"
    click ServiceReg "https://github.com/pitest/pitest-testng-plugin/blob/main/src/main/resources/META-INF/services/org.pitest/testapi.TestPluginFactory"
    click TestSuite "https://github.com/pitest/pitest-testng-plugin/tree/main/src/test"
    click Maven "https://github.com/pitest/pitest-testng-plugin/blob/main/pom.xml"
    click CI "https://github.com/pitest/pitest-testng-plugin/tree/main/.github/workflows"

    %% Styles
    classDef maven fill:#F7DC6F,stroke:#B7950B,stroke-width:2px;
    classDef plugincore fill:#AED6F1,stroke:#2471A3,stroke-width:2px;
    classDef service fill:#A9DFBF,stroke:#28B463,stroke-width:2px;
    classDef tests fill:#F5B7B1,stroke:#C0392B,stroke-width:2px;
    classDef ci fill:#FAD7A0,stroke:#D35400,stroke-width:2px;
    classDef external fill:#D2B4DE,stroke:#8E44AD,stroke-width:2px;
```
