რედაქტირება

Quickstart: generate Java unit tests with GitHub Copilot modernization

This quickstart shows you how to generate Java unit tests by using GitHub Copilot modernization.

Prerequisites

  • A GitHub account with GitHub Copilot enabled. You need a Free Tier, Pro, Pro+, Business, or Enterprise plan.
  • Java JDK for the project's JDK version.
  • Maven or Gradle to build Java projects.
  • A Git-managed Java project using Maven or Gradle.
  • For Maven-based projects: access to the public Maven Central repository.
  • Install the GitHub Copilot CLI:

    npm install -g @github/copilot
    
  • Install the GitHub Copilot modernization plugin:

    copilot plugin marketplace add microsoft/modernize-java
    copilot plugin install modernize-java@modernize-java
    

Note

An Azure account is required only for deploying resources to Azure, and isn't needed when using GitHub Copilot modernization to make code changes.

If you're using Gradle, only the Gradle wrapper version 5 or later is supported.

The Kotlin Domain Specific Language (DSL) isn't supported.

Generate unit tests

Use the following steps to generate unit tests:

  1. Open a Java project in Visual Studio Code.

  2. Open the GitHub Copilot Chat panel.

  3. Enter a prompt such as the following example:

    Generate unit tests for this Java project using #appmod-generate-tests-for-java
    

Use the following steps to generate unit tests:

  1. Open a Java project in IntelliJ IDEA.

  2. Open the GitHub Copilot Chat panel and ensure Agent Mode is selected.

  3. Enter a prompt such as the following example:

    Generate unit tests for this Java project using #appmod-generate-tests-for-java
    

Use the following steps to generate unit tests:

  1. Open a terminal and navigate to your Java project directory.

  2. Start the Copilot CLI:

    copilot --model claude-sonnet-4.6
    
  3. Enter a prompt such as the following example:

    Generate unit tests for this Java project using #appmod-generate-tests-for-java
    

The agent analyzes the project, identifies source files lacking unit tests, and generates a generate_tests.md work log that tracks progress.

Screenshot of Visual Studio Code that shows the test generation plan and work log.

Review the results

After test generation finishes, the work log shows a final summary that compares pre-generation and post-generation test results. This summary includes:

  • Number of new test files created
  • Total tests before and after generation
  • Pass or fail status for each generated test class

The agent generates tests that follow the project's existing test patterns and validates that all tests pass before it finishes.

Screenshot of Visual Studio Code that shows the post-generation test summary.

See also

GitHub Copilot modernization