Skip to main content

๐Ÿ” Changed Methods Only

Early PR and commit agents determine which code to generate tests for

This document explains how the --changed-methods-only flag and the CHANGED_METHODS_ONLY environment variable affect test generation behavior.


๐Ÿง  Core Test Selection Logicโ€‹

At a high level, Early always starts from the same base logic:

  • Identify public methods
  • Filter methods below the coverage threshold
    (currently treated as zero coverage)
  • Generate tests only for methods that meet these criteria

The changed-methods-only setting adds an additional filter layer on top of this logic.


For PR-based and commit-based agents, the default behavior is:

  • Generate tests only for public methods that were added or changed
  • Ignore unchanged methods, even if they are below coverage

This keeps test generation:

  • Focused on the current change
  • Faster and more predictable
  • Aligned with typical CI workflows

This behavior is enabled by default.


โš™๏ธ Configuration Optionsโ€‹

You can control this behavior using either a CLI flag or an environment variable.

CLI Flagโ€‹

--changed-methods-only true | false

Environment Variableโ€‹

export CHANGED_METHODS_ONLY=true | false

Both options are equivalent.


๐Ÿงช Behavior Matrixโ€‹

ModeWhat Gets Tested
true (default)Public methods that were added or changed and are below coverage
falseAll public methods below coverage, regardless of recent changes

๐Ÿ”ง When to Set falseโ€‹

You may want to disable changed-only filtering when:

  • Running repository-wide cleanup or refactoring
  • Backfilling tests for legacy code
  • Running scheduled or one-off coverage improvement jobs
  • Running PR or commit flows where you want broader test generation

In these cases, Early will generate tests for all eligible public methods, not just recently modified ones.


๐Ÿงช Example: GitHub Actionsโ€‹

env:
CHANGED_METHODS_ONLY: "false"

This forces test generation for all public methods below coverage.


๐Ÿงช Example: Jenkinsโ€‹

environment {
CHANGED_METHODS_ONLY = 'false'
}

Or inline before running the CLI:

export CHANGED_METHODS_ONLY=false
early generate-pr # or early generate-commit

๐Ÿ“Œ Notesโ€‹

  • This setting applies only after coverage and visibility filtering.
  • It does not affect how coverage is calculated.
  • For PR and commit agents, true is strongly recommended for day-to-day usage.
  • This setting applies only to PR and commit-based agents.
  • It is ignored by repository-wide agents such as generate-for-project.

โœ… Summaryโ€‹

SettingDefaultEffect
--changed-methods-onlytrueLimit test generation to changed public methods
CHANGED_METHODS_ONLYtrueEnvironment-based equivalent
Applies toPR / Commit agentsControls method selection scope

This option allows you to balance signal vs. coverage, depending on whether your goal is incremental validation or broad test generation.