GH-300 - Improve developer productivity with GitHub Copilot - Section 5.2

Generate unit and integration tests, identify edge cases, and write assertions with Copilot.

Use GitHub Copilot to generate unit and integration tests, surface edge cases a developer might miss, and write assertions. Recognise that generated tests must still be reviewed for coverage and correctness rather than accepted as complete.

Unit testsIntegration testsEdge casesAssertions

Practice question for this objective

Free sampleImprove developer productivity with GitHub Copilotmedium

A developer wants Copilot to generate a thorough unit test suite for an existing pure pricing function, and wants the suggestion to follow the project's own testing library and assertion style rather than a generic guess. Before prompting Copilot Chat, which preparation steps most improve the quality of the generated tests? Select TWO.

export function totalWithTax(net, taxRate) {
  return net + net * taxRate;
}
  • AOpen the function under test and an existing test file from the same project so Copilot sees the testing library, fixtures, and assertion style already in use as context. Correct
  • BAdd a content exclusion over the existing test directory so Copilot cannot read the old tests and is forced to invent a fresh, cleaner test structure of its own.
  • CSwitch the organisation to Copilot Enterprise first, because a higher plan is required before Copilot Chat is allowed to generate unit tests from a selected function at all.
  • DWrite a specific prompt that states the function's intended behaviour, the cases to cover such as zero and negative inputs, and the test framework the suite must target. Correct
  • EDelete the function's type annotations before prompting, since untyped code lets Copilot consider more possible behaviours and therefore produces a broader set of test cases.
Improve generated unit tests by giving Copilot relevant open files and a specific prompt naming behaviour, cases, and framework, since context and specificity shape the output. Copilot builds its prompt from open files and the instruction it is given, so opening the function alongside an existing test file supplies the conventions to follow while a specific prompt naming the behaviour, edge cases, and framework narrows the result, whereas exclusions, plan upgrades, and stripped types remove useful signal rather than adding it.

Why A is correct: Open relevant files give Copilot real context about the function and the project's testing conventions, so the generated suite mirrors the library and assertion style in use.

Why B is wrong: Content exclusions only remove files from context and never improve test quality, so hiding the existing tests strips away the very conventions the developer wants matched.

Why C is wrong: Test generation in Chat is available on paid Copilot tiers generally, so an Enterprise upgrade is not a prerequisite and does not change the quality of the prompt context.

Why D is correct: A specific prompt naming behaviour, target cases, and the framework narrows Copilot's output towards a focused, correct suite instead of a vague generic draft.

Why E is wrong: Removing type information takes away useful signal, so Copilot has less to reason about and tends to produce vaguer tests, not a broader or stronger suite.

See more GH-300 practice questions, answers explained.

More in this domain

Back to all Improve developer productivity with GitHub Copilot objectives, or the GH-300 cert hub.

Examworthy is not affiliated with or endorsed by GitHub. Original, blueprint-aligned practice material only.