Missing edge cases? Ask GitHub Copilot to propose tests

Supply a function, expected behavior and existing tests in your editor. Ask Copilot for test scenarios first, then generate and run test code.

Execution environment and usage

AI / software

GitHub Copilot

Where to operate

GitHub Copilot Chat inside a code editor; VS Code is the suggested starting path.

Getting started

  1. Install and sign in to GitHub Copilot in VS Code, then open a project copy.
  2. Supply relevant code context in Copilot Chat and enter the request for tests; review the response first.

Setup and plan requirements

Copilot access and a compatible editor. Running tests additionally needs the project runtime, dependencies and test tools. Reading code does not require execution permission.

Prompt portability limits

Reuse sanitized snippets and questions with another coding assistant. Workspace context, tool calls and test environments do not transfer automatically.

Usage limitations

This case does not require Agent mode or automatic shell execution. If you enable an agent separately, review file and terminal permissions.

Environment sources

適用情境 / When to use

Supply a function, expected behavior and existing tests in your editor. Ask Copilot for test scenarios first, then generate and run test code. Passing tests does not prove correctness or security.

步驟 / Steps

  1. Open the function, requirements and examples of existing tests.
  2. Review a proposed case list before asking for test code.
  3. Run the tests, inspect assertions and add important human-designed cases.

提示詞 / Prompt

Based on this function’s requirements and the existing test framework, propose normal, boundary and invalid-input cases first. If requirements and implementation conflict, ask rather than treating current behavior as correct. After I confirm, generate tests and explain what each assertion verifies.

留意事項 / Cautions

  • Passing tests does not prove correctness or security.
  • Do not expose credentials or run unreviewed code in production.

GitHub Docs:Writing tests with GitHub Copilot