73 / 87 · 02 AI-Augmented Test Design · Copilot and Cursor as Test-Writing Copilots← prev⊞ allnext →☰ Read as one page
11.3GitHub Copilot Workflow: Inline Test Completion
Copilot works best for completing individual tests when you provide strong naming conventions. It excels at filling in test bodies when you write descriptive test names.
The Pattern: Name-Driven Completion
# You type the test name, Copilot completes the body
def test_shipping_cost_rejects_negative_weight(self):
# Copilot autocompletes:
with pytest.raises(ValueError, match="weight must be positive"):
calculate_shipping_cost(weight_kg=-1, destination="US", is_express=False)
def test_shipping_cost_applies_express_multiplier(self):
# Copilot autocompletes:
result = calculate_shipping_cost(weight_kg=5, destination="US", is_express=True)
assert result["cost_usd"] == 22.50 # (5 + 2*5) * 1.5
assert result["estimated_days"] == 3 # ceil(5 / 2)
def test_shipping_cost_handles_zero_weight(self):
# Copilot autocompletes:
result = calculate_shipping_cost(weight_kg=0, destination="US", is_express=False)
assert result["cost_usd"] == 5.00 # Base rate only
assert result["estimated_days"] == 5
Copilot Strengths
- Speed for individual tests. When you know what to test and just need the code, Copilot's autocomplete is fastest.
- Pattern continuation. After writing 2-3 tests in a file, Copilot learns the pattern and generates similar tests with high accuracy.
- Fixture inference. If you have fixtures imported at the top of the file, Copilot uses them correctly in generated tests.
- Zero context switching. You stay in your editor the entire time.
Copilot Weaknesses
- Limited context. In inline-completion mode, Copilot primarily sees the current file and open tabs. It will not pull in your OpenAPI spec, database schema, or test helpers from other directories unless you open them.
- No execution. Copilot cannot run the tests it generates or fix failures.
- Happy-path bias. Without explicit prompting, Copilot tends to generate positive test cases.
- No spec awareness. Copilot does not know your acceptance criteria unless they are in a comment above the test.
Pro Tip: Comment-Driven Generation
Compensate for Copilot's limited context by writing detailed comments:
# Test the POST /api/v2/orders endpoint
# Required fields: items (array, min 1), shipping_address, idempotency_key (UUID)
# Auth: JWT Bearer token with "customer" role
# Error codes: 400 (validation), 401 (no auth), 403 (wrong role), 409 (duplicate key)
class TestCreateOrder:
"""Tests for POST /api/v2/orders."""
def test_should_create_order_when_valid_payload(self):
# Copilot now has enough context to generate a reasonable test body