Learning resourcesReviewed · GitHub

Generating unit tests

This GitHub tutorial teaches developers to draft Python unit tests with Copilot Chat, but its sample tests need review for missing cases. It demonstrates a /tests prompt and a unittest suite for price validation, including exception checks and an accepted upper boundary.

Researched 15 Nov 2026

In short.

Generating unit tests is a GitHub tutorial for developers learning to create tests with Copilot Chat, with an illustrative suite that needs human review before use. It pairs a Python price-validation function with a prompt requesting successful cases, failures and boundary cases. The sample repeats the zero-input test and checks only one accepted input, 1000. Responses can vary, and no execution results or coverage measurements are supplied.

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

Coverage is the complete selected documentation page at [https://docs.github.com/api/article/body?pathname=/en/copilot/tutorials/copilot-cookbook/testing-code/generate-unit-tests], including its example-response notice and further-reading references. Linked pages, broader Copilot documentation and external terms are excluded. Installation, editor compatibility, generated responses, test execution and measured coverage remain unassessed.

The overview

Identity

Generating unit tests is a GitHub Copilot documentation tutorial about using Copilot Chat to draft tests for a function. The selected resource is the complete page at [https://docs.github.com/api/article/body?pathname=/en/copilot/tutorials/copilot-cookbook/testing-code/generate-unit-tests]. It teaches a feature through a Python example.

Assessment

The tutorial is useful as a small, concrete introduction: readers can see the function, request and example response together. Its practical limit is test completeness. The displayed suite supplies a starting point, but neither its coverage nor its correctness is demonstrated by a reported test run.

Users

Python developers beginning to use Copilot Chat can learn how to request tests for expected behavior, rejected inputs and boundaries. Experienced developers may find the prompt useful as a starting pattern, but the page does not address larger test suites, database integration, mocking or repository-specific testing conventions.

Capabilities

The page describes Copilot Chat providing a testing strategy followed by generated tests. Its example uses unittest to check ValueError exceptions and their messages, and to check that the maximum allowed price does not raise ValueError. Copilot may also offer to configure unit testing when first asked; that configuration is not demonstrated.

Using it

Requirements

Following the interaction requires access to Copilot Chat and the function as context. Using the displayed test code also requires a Python environment in which unittest and validate_price can be imported. The sample imports validate_price from generate_unit_tests. Supported editors, Python versions, account eligibility and Copilot plans are not specified.

Mechanism

The developer supplies a function and asks Copilot Chat to generate tests covering success, failure and edge cases. The generated assertions express expectations about that function. GitHub explicitly warns that responses are nondeterministic, so the displayed suite is an example rather than a guaranteed output.

Setup

Provide validate_price as context and submit the documented /tests prompt. The walkthrough assumes declining Copilot's possible offer to configure unit tests. For the displayed import to work, the function must be available from a module named generate_unit_tests, or the import must be adapted to the project. Full installation and editor configuration instructions are absent.

Example

The supplied validate_price function raises ValueError when price is at or below zero or above 1000. The prompt is: /tests Generate unit tests for this function. Validate both success and failure, and include edge cases.

The example response tests 0, -10 and 1500 as rejected inputs, repeats the test for 0, and checks that 1000 does not raise ValueError. Although the scenario mentions validation before a database update, the displayed function and tests contain no database interaction.

Assessment & evidence

Limitations

Two tests exercise the same zero input, so they do not add distinct input coverage. The suite lacks a typical accepted value between zero and 1000, a small positive value near zero, and a value just above 1000. These are identifiable gaps in the displayed example, not predictions about every Copilot response.

The page does not define expectations for nonnumeric inputs or non-finite numbers. It supplies no test-run output, coverage report or evidence that the generated tests detect an incorrect implementation.

Reasoning

For ordinary finite numeric inputs, the shown comparisons allow values greater than zero and at most 1000. A useful review therefore considers rejected inputs, both boundaries and accepted values inside that range. The sample covers several rejected values and the accepted upper endpoint, but its repeated zero case does not establish broader coverage. Intended business rules still need to be checked independently.

Alternatives

Writing the unittest cases directly is a practical alternative for this small function, inferred from the displayed test structure. The tutorial does not compare Copilot with other assistants or testing frameworks, so relative quality, effort and cost are unknown. Its linked further reading concerns Copilot prompting and best practices; those pages are outside the selected scope.

Evidence

The evidence is the complete supplied GitHub documentation page, retained as selected-page.txt. It includes the function, prompt, illustrative response, response-variability notice and further-reading links. It supports inspection of the displayed code and instructions, but provides no independent evaluation or execution results.

Access & freshness

Costs

The page provides no prices, subscription requirements, usage allowances or billing details. Copilot access costs are unknown from this evidence. It also provides no measured time savings or comparison of manual and generated test-writing effort.

Rights

The selected text contains no licence or redistribution terms for the documentation or sample code. It also does not establish the terms governing generated tests. Reuse permissions and applicable conditions remain unknown from this page.

Freshness

The supplied snapshot was captured on 15 November 2026 at 15:21:01.851 UTC. The selected text does not state a publication date, last-update date, Copilot model identifier or applicable software versions. Compatibility with a particular current Copilot environment remains unassessed.

Actions

Use the prompt as a starting point, then compare the proposed assertions with the intended price rules. Adapt the import, remove the duplicate zero case, and add distinct cases such as an ordinary accepted price and values close to either boundary. Define any requirements for unusual input types before adding those tests.

Run the reviewed suite in the target project and inspect the results before relying on it. Neither the Copilot interaction nor the displayed code was executed for this assessment.

Evidence for this report

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