Introduction

Completed

Unit testing is a crucial aspect of software development that ensures the functionality of individual components within a system.

This module introduces how to generate unit tests with GitHub Copilot in Visual Studio Code. The module focuses on using the Chat view in Agent mode—with Ask and Plan modes available for analysis and planning—and ghost text suggestions to create and maintain unit tests for the xUnit testing framework. Visual Studio Code and the C# Dev Kit extension provide the environment that hosts your test project and runs the tests.

Imagine you're a software developer working on a large codebase. Your team is tasked with ensuring code reliability. You determine that unit tests are needed for most of the codebase. However, creating unit tests manually can be time-consuming and error-prone. You need a tool that helps you develop unit tests quickly and accurately. The tool should also help identify edge cases and boundary conditions. You hear that GitHub Copilot can accelerate the development of unit tests and help to identify edge cases. You're looking forward to developing unit tests more quickly and accurately using GitHub Copilot.

The topics covered in this module include:

  • Using Visual Studio Code and the C# Dev Kit to host and run unit tests.
  • Generating unit tests in the GitHub Copilot Chat view using Agent mode (with Ask mode for upfront analysis).
  • Planning and automating multi-file test workflows with the Plan and Agent agents.
  • Extending tests with ghost text suggestions and fixing failing tests with GitHub Copilot.
  • Developing unit tests for a C# application end to end.

After completing this module, you’ll be able to:

  • Describe how Visual Studio Code, the .NET SDK, and the C# Dev Kit support unit testing for C# projects.
  • Use Agent mode in the GitHub Copilot Chat view to generate unit tests for files and selections, and use Ask mode to explore testing options first.
  • Use the Plan agent to design a test strategy and the Agent to automate multi-step test workflows.
  • Use ghost text suggestions, Test Explorer, and the /fixTestFailure slash command to extend coverage and repair failing tests.
  • Apply GitHub Copilot's capabilities to streamline unit test development for a C# application in Visual Studio Code.

Important

To complete this GitHub Copilot training, you must have an active subscription for GitHub Copilot in your personal GitHub account (includes the GitHub Copilot Free plan), or you must be assigned to a subscription managed by an organization or enterprise. Module activities may include GitHub Copilot suggestions that match public code. If you're a member of an organization on GitHub Enterprise Cloud who has been assigned a GitHub Copilot subscription through your organization, the setting for suggestions matching public code may be inherited from your organization or enterprise. If your account blocks suggestions that match public code, module activities may not work as expected.