Skip to main content

Introduction to GitHub Copilot

Step 2
⏱ 15 min🟢 Beginner

GitHub Copilot is an AI-powered coding assistant built on large language models. Before using it for test generation, you need to understand what it is, how it reasons about your code, which interaction modes exist, and the full command vocabulary available to you in VS Code.

How GitHub Copilot Works
📝Your Code + Context
sent as prompt▸
🔌Copilot Extension
forwarded to▸
🧠LLM (GPT / Claude / Gemini)
generates▸
✨Suggestion / Response
rendered in▸
💻Your Editor

What GitHub Copilot Is​

GitHub Copilot is an AI pair programmer embedded in your editor. It reads the code you have open — the current file, related files, comments, and your cursor position — and predicts what you likely want to write or asks you clarifying questions. It does not execute your code autonomously unless you use Agent mode; otherwise it reasons purely from the context window it receives.

PropertyDetail
Available modelsGPT, Claude, Gemini and more, switchable per session. The lineup changes often: see what's changed since the workshop
Context windowUp to ~64 k tokens of surrounding code, comments, and open files
Supported IDEsVS Code, JetBrains, Visual Studio, Neovim, Xcode, Eclipse, and more
Supported languagesAll major languages; strongest for JavaScript/TypeScript, Python, Go, Java, C#
Data privacyPrompts and suggestions are not retained for model training on Business/Enterprise plans

Interaction Surfaces​

Copilot surfaces in VS Code in several ways. Each targets a different workflow:

SurfaceShortcutBest for
Inline completionsJust start typing — ghost text appears automaticallyBoilerplate, function bodies, one-liners; accept with Tab
Next Edit Suggestions (NES)Tab to navigate & accept gutter arrow suggestionsCopilot proactively predicts the next edit location across files
Inline Chat⌘I / Ctrl+ITargeted edits — refactor, add tests, or fix a specific code region
Chat sidebar⌃⌘I / Ctrl+Alt+IConversations, code generation, explanations, multi-file tasks
Quick Chat⇧⌥⌘L / Ctrl+Shift+Alt+LFast one-off questions without leaving your current context

Chat Modes​

The Chat sidebar has three modes, selectable from the dropdown at the bottom of the chat view:

ModeWhat it doesWhen to use
AskAnswers coding questions and provides code suggestionsUnderstanding code, exploring ideas, getting help with syntax
AgentAutonomously edits files, runs terminal commands, iterates until task is completeComplex multi-step tasks — generate tests, refactor, fix bugs end-to-end
PlanCreates a detailed implementation plan before touching any codeLarge features where you want to review the approach before Copilot acts

What Changed in Modern Copilot​

If your mental model is from older Copilot releases, these are the highest-impact shifts to adopt before using Copilot for production test workflows.

ThenNow
Mostly inline autocompleteAsk, Plan, and Agent modes support multi-step test generation and refactoring workflows
Manual model picking for most tasksAuto model selection is usually the best default for quality, reliability, and cost balance
One-off prompts with limited operational controlsAgent sessions are manageable artifacts: monitor logs, steer mid-run, and continue in VS Code or CLI
Tooling mostly local to editor contextMCP and cloud-agent integrations can bring GitHub, browser, and platform context directly into workflows
Few safety boundaries around agentic executionSandboxing, least-privilege tools, and automation policies are core governance controls

Agent Management in Practice​

Modern Copilot workflows are not just about starting an agent task. GitHub now emphasizes managing agent sessions as ongoing work: start tasks, inspect logs, steer mid-run, and resume the work in your local tools when needed.

CapabilityWhy it matters
Run multiple sessionsUseful when one agent investigates a flaky test while another drafts a fix or refactor
Steer mid-sessionLets you narrow scope, request a safer tool choice, or force the agent to inspect a specific failure signal
Review logs and outputsImportant for trust: you should see what the agent tried before you accept any code or PR changes
Open in VS Code or Copilot CLIHelpful when cloud-agent work needs local follow-up, faster iteration, or deeper debugging against your environment
Workshop rule

Use Plan first for risky or broad work, then Agentfor execution, and always review session logs or diffs before treating the result as trustworthy.

Model Selection for Testing Tasks​

Model availability changes by plan and rollout, so optimize for task fit instead of memorizing one "best" model. Pick the smallest scope and cheapest prompt that still produces reliable output, then escalate only when complexity increases.

Task profileRecommended approachEscalate when
Fast test draftUse a lightweight model path with narrow #file contextGenerated assertions are vague or miss negative paths
Bug triage and flaky failuresUse a stronger reasoning model with explicit failure outputRoot cause still unclear after one focused iteration
Multi-file refactor + testsRun Plan mode first, then Agent mode for implementationTask touches contracts, auth, or shared utilities

When to Use Auto Model Selection​

Current GitHub guidance is to prefer Auto when you do not have a strong reason to pin a specific model. Auto routes work based on task complexity, current model availability, and policy restrictions, which usually improves reliability and reduces unnecessary cost.

ChoiceUse it whenWatch out for
AutoDaily chat, CLI, and agent work where you want the best default balance of speed, quality, and availabilityAdmins may restrict which models Auto can choose; evaluation models may also be excluded by policy
Pin a specific modelYou are reproducing an issue, comparing outputs, or intentionally using a stronger reasoning pathPinned models can cost more and may hit rate limits sooner than Auto
Practical default

Start with Auto for test generation and review loops. Switch to a pinned stronger model only when the task is clearly stuck, ambiguous, or spans multiple files and contracts.

Slash Commands (VS Code)​

Type / in the Chat prompt box to see all available commands. The most useful ones for everyday and testing workflows:

CommandWhat it does
/testsGenerate unit tests for the selected code
/explainExplain how the code in the active editor works
/fixPropose a fix for problems in the selected code
/fixTestFailureFind and fix a failing test automatically
/newScaffold a new project from a natural-language description
/clearStart a fresh chat session
/helpQuick reference and basics of using Copilot Chat

Chat Participants (@)​

Prepend @ to route your question to a domain expert. Copilot can also infer the right participant automatically.

ParticipantSpeciality
@workspaceUnderstands your entire project structure, patterns, and cross-file relationships
@githubGitHub-specific skills: search issues, PRs, commits, web search
@vscodeVS Code commands, settings, and extension APIs
@terminalShell commands and integrated terminal context
@azureAzure services — deploy, configure, and manage cloud resources (preview)

Context Variables (#)​

Type # in the prompt box to attach specific context to your question. Copilot uses only what you include:

VariableWhat it attaches
#fileThe full content of the current file
#selectionThe currently highlighted text
#functionThe function or method containing the cursor
#classThe class containing the cursor
#projectHigh-level project context (structure, dependencies)
#symThe symbol (type, function, variable) at the cursor
#pathThe file path of the active editor
#lineThe current line of code

Keyboard Shortcuts Cheat Sheet​

ActionmacOSWindows / Linux
Accept inline suggestionTabTab
Dismiss suggestionEscEsc
Accept next word⌘→Ctrl+→
Next suggestion⌥]Alt+]
Previous suggestion⌥[Alt+[
Open suggestions panelCtrl+EnterCtrl+Enter
Open Inline Chat⌘ICtrl+I
Open Chat sidebar⌃⌘ICtrl+Alt+I
Open Quick Chat⇧⌥⌘LCtrl+Shift+Alt+L

Tokens and the Context Window​

Every piece of text sent to the LLM — your code, comments, chat history, and Copilot's own instructions — is converted into tokens. A token is roughly 3–4 characters of English text or a short code symbol. The context window is the total number of tokens the model can consider at once (~64 k for most Copilot models).

ConceptWhat it means for you
Token budgetLarge files, long chat histories, and many open tabs all consume tokens — leaving less room for Copilot to reason
Context quality beats quantityOne focused #file reference beats five loosely-related open tabs
Token cost in Agent modeEach Agent-mode prompt consumes GitHub AI Credits; keep tasks focused to avoid burning budget on irrelevant context
MCP toolsets consume tokens tooEnabling only the MCP toolsets you need improves accuracy and frees context for actual coding
Rough token estimates:
1 line of TypeScript ≈ 10–20 tokens
1 typical test file ≈ 300–600 tokens
64 k context window ≈ ~200–300 lines of dense code

Rule of thumb: the more precise your #selection, the better the suggestion.

How to Write Better Prompts​

  • Write a comment first. A line like // test that getUser returns 404 when user is not found gives Copilot a clear target before it tries to complete code.
  • Use #file or #selection. Explicit context variables beat relying on Copilot to infer what you mean.
  • Mention the framework. Saying "using Jest with TypeScript" avoids mismatched syntax or wrong assertion libraries.
  • Use Agent mode for end-to-end tasks. Ask it to "generate tests for all exported functions in #file and run them" — it will edit, run, and fix failures on its own.

A Minimal Example​

Comment-driven inline completion — type the comment, press Tab to accept:

// function that adds two numbers
function add(a: number, b: number): number {
return a + b;
}

// test that add returns the correct sum
it('returns the correct sum', () => {
expect(add(2, 3)).toBe(5);
});

Or use the Chat sidebar with a context variable:

/tests #file write Jest unit tests covering happy path and edge cases
HintHands-on Challenge — Trigger Your First Suggestion

Open any TypeScript or JavaScript file in your editor. Type the following comment and wait a moment:

// function that checks if a string is a palindrome

Copilot should suggest a function body. Press Tab to accept it, then open Inline Chat (⌘I / Ctrl+I) and type:

/tests write Jest tests for isPalindrome including edge cases

Accept the generated tests and run them with npm test. You've completed your first Copilot-assisted test generation!

Key Takeaways​

  • Copilot supports multiple LLMs (GPT, Claude, Gemini and more) — switchable per session, and the lineup changes often.
  • Five surfaces: inline completions, NES, Inline Chat, Chat sidebar, Quick Chat.
  • Three chat modes: Ask (Q&A), Agent (autonomous), Plan (design-first).
  • Every input consumes tokens — precise context (#selection, #file) beats broad context.
  • Use /tests, /fix, and /fixTestFailure slash commands for testing workflows.
  • Always review suggestions — Copilot can confidently produce incorrect or insecure code.
  • Later in this workshop, "Configuring Copilot for Your Team" covers MCP servers, GitHub skills, and customization files (copilot-instructions.md, AGENTS.md, prompt files, chat modes) that bake team conventions into every response.
Done with this step? Mark it to track your progress.