Domain 5: Improve Developer Productivity with GitHub Copilot (10โ15%) โ
โ Domain 4 ยท Next Domain โ
Exam Tip
This domain is practical โ the exam presents real-world scenarios and asks how Copilot should be used to solve them. Know the right Copilot feature for each task: inline suggestions for generation, Chat for explanation, /tests for testing, /fix for debugging.
Code Generation, Refactoring, and Documentation โ
Code Generation โ
Copilot generates code from:
- Comments: Describe what you want in a comment โ Copilot fills in the implementation
- Function signatures: Write the function name and parameters โ Copilot generates the body
- Open files context: Copilot infers patterns from existing code in your project
Best uses: Boilerplate code, repetitive patterns, scaffolding new functions/classes, generating CRUD operations
Refactoring โ
Use Copilot Chat for refactoring tasks:
/fix โ Fix a specific issue in selected code
"Refactor this function to use async/await" โ general refactoring
"Convert this class to use dependency injection" โ architectural refactoringAgent Mode or Edit Mode for cross-file refactoring (e.g., renaming an interface that's used in 10 files)
Documentation Generation โ
/doc โ Generate inline documentation for selected code
"Write a README for this module" โ via Copilot Chat
"Add JSDoc comments to all exported functions" โ Agent ModeReducing Context Switching โ
One of Copilot's highest-value use cases is keeping developers in flow:
- Learn as you code: Ask Copilot to explain unfamiliar APIs or libraries without leaving the IDE
- Generate sample data:
"Give me 5 sample JSON objects for a user profile"โ no need to switch to a browser - Modernize legacy code: Ask Copilot to translate Python 2 โ Python 3, or convert callbacks to async/await
- Shell command help: Use Copilot CLI instead of searching Stack Overflow for CLI syntax
Testing with GitHub Copilot โ
Generating Unit Tests โ
# Select your function, then use:
# /tests in Copilot Chat
# or write a comment: "# Test that get_email returns None for invalid input"Copilot can generate:
- Happy path tests (valid inputs)
- Edge cases (empty strings, None, boundary values)
- Error cases (exception handling)
Identifying Edge Cases โ
Ask Copilot Chat: "What edge cases should I test for this function?"
Copilot will enumerate cases like:
- Empty input / null
- Very large inputs
- Boundary conditions (e.g., exactly at the limit)
- Invalid types
- Concurrent execution scenarios
Writing Assertions โ
# Copilot can generate assertion-level tests:
# "Write assertions to verify the returned dict has keys 'id', 'email', 'role'"Security Improvements and Performance Optimizations โ
Security-Aware Code Review โ
Use Copilot Chat to review code for security issues:
"Review this function for SQL injection vulnerabilities"
"Is this code vulnerable to XSS?"
"Suggest a more secure way to store this password"Performance Optimizations โ
"Rewrite this loop using vectorized NumPy operations"
"Optimize this SQL query to avoid N+1 selects"
"Replace this O(nยฒ) algorithm with an O(n log n) approach"Trap
Copilot can suggest security and performance improvements but cannot guarantee they are correct. Always test and review AI-generated security changes with a security expert.
Domain 5 Quick Quiz
Which Copilot Chat command generates unit tests for selected code?
(Click to reveal)/tests โ generates unit tests for the currently selected code block.