Learning resourcesReviewed · GitHub

Writing tests with GitHub Copilot

This GitHub tutorial teaches developers to draft Python tests with Copilot, but generated tests need human review and its integration example uses a simulated service. It covers unittest, notification mocks, prompts for missing cases, the /tests command and project context through Copilot Spaces.

Researched 24 Nov 2026

In short.

This GitHub tutorial helps developers learn AI-assisted test writing, but its examples require review and do not establish that a real external service works. It progresses from Python unit tests to notification-call assertions using unittest.mock, then shows how to request missing cases and supply project context. Its practical value is the sequence of focused requests and revisions. No code was executed, and the page supplies no measured coverage, productivity results or real-service test results.

Researched and written by an AI model and checked by a second AI model. How it works

Coverage includes the complete selected documentation page at [https://docs.github.com/api/article/body?pathname=/en/copilot/tutorials/write-tests], including its expanded code example and Copilot Spaces section. Linked plan, extension-installation and Spaces documentation are excluded. No explicit licence or redistribution notice appears in the supplied text. No code or commands were executed; generated-output quality, compatibility, coverage and live-service behavior remain unassessed.

The overview

Identity

Writing tests with GitHub Copilot is a GitHub Docs tutorial about using the coding assistant to generate and improve tests. The resource is the instructional page, rather than Copilot itself. Its worked examples use a Python BankAccount class and the unittest framework.

Original source: [https://docs.github.com/api/article/body?pathname=/en/copilot/tutorials/write-tests].

Assessment

The tutorial provides a concrete starting point for developers who want to turn testing requirements into Copilot requests. It shows both an initial generated suite and follow-up requests that add missing behavior, making the revision process visible.

Its strongest lesson is that test generation is iterative. Its examples support learning prompting and assertions; they do not demonstrate exhaustive coverage, production readiness or a measured improvement over writing tests manually.

Users

Beginners with some Python knowledge can follow the small account example to learn how to request tests for valid inputs, rejected inputs and exceptions. Familiarity with classes and basic test assertions will make the code easier to understand.

Experienced developers can adapt the requests for narrower behaviors, existing test conventions and interactions with dependencies. The page does not develop a testing strategy for a large application or a particular production framework.

Capabilities

The guide demonstrates requesting unit tests, specifying edge cases and exceptions, asking how to run a suite, and requesting additional cases. It also describes /tests for the open file and opening existing tests in adjacent editor tabs to communicate the project's testing conventions.

For dependency interactions, it shows mocks that check whether notify receives an expected message or remains uncalled after invalid input. Its Copilot Spaces section describes supplying modules, existing tests and coverage information as task context.

Using it

Requirements

The page lists a GitHub Copilot subscription plan, Visual Studio, Visual Studio Code or a JetBrains IDE, and the GitHub Copilot extension. Following the worked examples also requires a Python environment capable of running unittest.

Python, IDE and extension versions are unspecified. The page does not establish which plans include the described features, their usage allowances, or any additional access requirements for Copilot Spaces.

Mechanism

The approach combines implementation context with explicit descriptions of the behaviors to check. Requests identify the class or method, relevant boundaries, expected exceptions and dependency calls. For more involved behavior, the tutorial splits generation into smaller requests and asks for omissions afterward.

Mocks replace the notification dependency so assertions can inspect calls without connecting to a service. Asking Copilot about missing cases produces suggestions; it does not itself measure executed code coverage. The model and internal generation process are unspecified.

Setup

The tutorial starts with bank_account.py in a GitHub repository. After requesting unit tests, it directs the reader to save them as test_bank_account.py and run python -m unittest test_bank_account.py.

The notification example extends the account class with an optional notification_system dependency. Its generated tests go in test_bank_account_integration.py, with the suggested command python -m unittest test_bank_account_integration.py. Detailed extension installation instructions are linked separately and are not included in the supplied page.

Example

One example constructs an account with a balance of 100 and a mock notification system, then deposits 50. The assertions expect a balance of 150 and exactly one notification containing the deposit amount and resulting balance.

Follow-up examples cover zero and negative deposits, withdrawals and rejected withdrawals. For invalid amounts, the assertions expect ValueError and no notification call. These are illustrative assertions from the page; no execution results were supplied or independently produced.

Assessment & evidence

Limitations

The notification examples use a Mock in place of NotificationSystem. They are designed to check the account's expected calls, so they do not establish compatibility with an actual service, successful message delivery or behavior during service failures.

The first unit-test suite omits zero deposits and zero withdrawals even though the implementation rejects both. Later notification examples include those cases. Other behaviors, such as notification failures and withdrawals exactly equal to the balance, are not covered by the displayed suites.

No measured coverage or test execution output is provided. Passing the displayed assertions would establish only the behaviors those assertions check, not complete correctness.

Reasoning

The examples support using Copilot to draft tests when a developer can specify and inspect the expected behavior. Naming a particular method, dependency and expected call gives a more concrete target than asking for comprehensive tests alone.

The missing cases in the initial suite show why a broad request is not evidence of completeness. Expected results should come from the intended requirements, with generated assertions checked against those requirements rather than accepted because they match the implementation.

Alternatives

Within Copilot, the page presents several approaches: explicit Chat requests for detailed requirements, /tests for generating tests around the open file, and Spaces for supplying task-specific project context. Adjacent test files offer another way to communicate existing conventions.

The page provides no comparison with other coding assistants, testing frameworks or manual test writing. Relative quality, cost and speed are unknown.

Evidence

The evidence is the complete supplied GitHub Docs tutorial at [https://docs.github.com/api/article/body?pathname=/en/copilot/tutorials/write-tests]. It includes implementation snippets, sample requests, illustrative generated tests and suggested execution commands.

The page does not include terminal receipts, measured coverage, comparative benchmarks or independent evaluations. Statements about productivity and better suggestions are not accompanied by measurements.

Access & freshness

Costs

The page requires a GitHub Copilot subscription plan but gives no prices, billing terms, request allowances or feature entitlements. Whether a particular reader needs a paid plan for the described workflow is unknown from this evidence.

No total adoption cost or measured time saving is established.

Rights

The supplied page contains no explicit licence or redistribution terms for its prose and code examples. It also does not establish ownership, licensing or other usage terms for code generated by Copilot.

Reuse and redistribution permissions therefore remain unknown from this page.

Freshness

The supplied page was captured on 24 November 2026. Its text gives no publication date, last-update date or exact Copilot, IDE or Python version.

The capture date does not establish when GitHub last revised the instructions. Continued availability and behavior of /tests, editor context handling and Copilot Spaces are not independently established.

Actions

Start with one small behavior and provide the implementation alongside representative existing tests. Specify valid inputs, boundary values, expected exceptions and dependency calls. Review the generated assertions and add independently identified omissions before running the suite.

For the account example, inspect zero amounts, exact-balance withdrawals and whether rejected operations preserve the balance. If real notification behavior matters, add tests against the actual supported integration or its test environment; mock-call assertions cannot establish delivery.

Evidence for this report

selected-page.txtselected · checked 2026-11-24