published fresh until

GitHub Copilot: Add unit tests for uncovered error paths

Summary Give Copilot the module, an existing test, and the error contract; then add tests that expose a missing guard, swallowed failure, or unwanted side effect. Review actual runner output and compare each assertion with the error contract. Use the Copilot harness in VS Code 1.145

Not for Copilot cloud-agent dependency setup; see copilot-cloud-agent-setup-steps-preinstall-deps. GitHub Copilot test passes broken handler false positive async rejection mock assertion error paths.

For your agent
claude mcp add --transport http --scope user whatworks https://whatworks.dev/mcp

Read-only, no account. Sign-in is only for trial reports: /connect.md

What this thread does

Do first: select the Copilot harness in VS Code, then identify the existing test runner, module command and uncovered error contract before editing.

Short answer

As of November 2026, this workflow uses VS Code 1.145. Keep the module real, arrange failures at its dependency boundary, and require a regression test that fails when the handler is deliberately broken.

Choose / don't choose

  • Unit test: choose for malformed input, controlled rejections or timeouts whose behavior belongs to this module; don't call a live dependency to create a deterministic error.
  • Integration/contract check: choose when the question is the real provider's error shape, adapter wiring or timeout behavior; don't infer that behavior from a mock (testing guide, mock boundary).
  • Existing framework: choose the repository's runner; don't install a second one to accommodate generated code (GitHub guide).

Not for: Copilot cloud-agent dependency setup; see copilot-cloud-agent-setup-steps-preinstall-deps.

Settings that matter

Setting or flagValue / defaultApplies toSource
.github/copilot-instructions.mdRecord framework, exact command/directory, mocking convention and required error assertionsCurrent Copilot harnessinstruction formats
.github/instructions/**/*.instructions.md, applyToFile-scoped instruction globs covering source and tests; ** covers all files; no default patternCurrent Copilot harnessscope
chat.tools.terminal.autoApprovetrue auto-approves a matched command; false requests review; allow only the intended local test commandCurrent VS Code approval docsterminal rules
chat.agent.sandbox.enabledon; default off; inspect effective policy in a fresh sessionCurrent Copilot sandboxsandbox
chat.agent.sandbox.network.allowNetworkfalse for isolated unit tests; default trueCurrent Copilot sandboxnetwork
chat.agent.sandbox.allowUnsandboxedCommandsfalse removes outside-sandbox fallback; default trueCurrent Copilot sandboxfallback

Use Manual permissions and review other tool/URL approvals. Terminal command rules are best-effort: the Copilot runtime can approve read-only or sandboxed commands before those rules. They do not enforce review of every dependency edit or network tool (approvals). Keep manifests unchanged during test generation and review their diff explicitly.

Order of operations

1. Run the existing focused suite; record prior failures. Attach the real module and one nearby test. Define the missing branch's required error/result, cleanup, and forbidden success effect. 2. Generate only the case and its dependency fixture. Demonstrate failure on the real defect; if behavior already passes, temporarily break the specific handler and require this case to fail, then restore it. This mutation check is an application review policy based on checking assertions, not a Copilot feature. 3. Reject a test that merely checks its own mock or derives its expectation from the production result. Return a promise from your test, and Jest will wait for that promise to resolve; prefer await expect(...).rejects..., or use expect.assertions(1) for catch-only assertions so unexpected fulfillment cannot pass (async completion). 4. After accepting the failing regression, repair production behavior as a separate reviewed change. Rerun the targeted case, existing success case, then the related suite. Check skipped counts, production diff and actual runner output (testing guide).

Known failures and fixes

Error or symptomCauseFixSource
Test passes with broken handler (symptom)Mock only the dependency; assert the public contract and required absence of effectsassertion review, Jest mocks
Async rejection assertion never runs (symptom)Omitting return/await lets the test complete before the promise resolves or rejectsAwait/return the operation and rejection matcher; count expected catch assertionsJest async
Agent reports pass, terminal shows failure (symptom)Tool output reports success while the terminal shows failuresInspect raw output and discovered/skipped countsTabberwocky, February 11, 2025, #4984 (closed December 8, 2025 as completed)

In Test Explorer use Show Output and, when supported, Test: Show Inline Coverage (testing UI).

Additional references: Identify the testing setup, CLI's code --version, Testing → Test coverage, Review assertions and coverage, Run and debug tests.

Missing

  • Coverage alone cannot show that an assertion catches a defect; the testing guide now explicitly confirms this.
  • The older report includes agent-prepared material; it is a caution, not evidence of a current editor defect.
  • No permission setting establishes mandatory review before every dependency change or external service call across all tools. Combine network isolation, tool permissions, bounded file scope and explicit diff review; do not claim terminal approval rules alone provide that gate.
  • The module/framework/commands are project-specific. Jest examples apply only to repositories already using Jest.

Checked

2026-11-24; editor release, GitHub/VS Code testing guides, instruction/approval/sandbox references, Jest async/mock references, CLI reference and contributor report read. No editor agent or module tests executed.

Started from a post by @Microsoft, packaged by the editor. Original post

Subjects

More in agent workflows

For agents

Copy a short instruction for an agent that has WhatWorks connected, or open this page as Markdown.

# GitHub Copilot: Add unit tests for uncovered error paths
Summary: Give Copilot the module, an existing test, and the error contract; then add tests that expose a missing guard, swallowed failure, or unwanted side effect. Review actual runner output and compare each assertion with the error contract. Use the Copilot harness in `VS Code 1.145`
Copy for agent
get the whatworks thread github-copilot-unit-tests-uncovered-error-paths and help me try it

Follow this thread

Following tells you when the verdict changes, a new version ships or a new option is added. Your agent mentions it the next time you ask WhatWorks.

Sign in with GitHub to follow. Nothing is posted for you.

Sign in with GitHub

Or ask your agent
follow the whatworks thread github-copilot-unit-tests-uncovered-error-paths
WhatWorks

Connect your agent MCP

Paste this into your agent

Connect me to WhatWorks: add https://whatworks.dev/mcp/login and sign me in so I have an account. Steps: https://whatworks.dev/connect.md.

Or run this in your terminal
  • Claude Codeclaude mcp add --transport http --scope user whatworks https://whatworks.dev/mcp/login && claude mcp login whatworks
  • Codexcodex mcp add whatworks --url https://whatworks.dev/mcp/login && codex mcp login whatworks