Unit tests are one of the very important tools in our developer arsenal to get peace of mind. But many developers are often neglecting this step, often by lack of time or motivation to have sufficient coverage on their code. This is difficult, because it's one of these features that you miss the most when you really, really need it. For example, unit tests are critically important when a feature of a referenced library changes, because a new version is released. Or, when a portion of code is refactored, to make sure that the rest of the code is not negatively affected, and still works as expected.
In the new video I just posted, my colleague Gwyn "GPS" Peña-Siguenza demonstrates how GitHub Copilot can create a unit test by using the "slash test" command that we already saw in previous posts.
Why take advantage of Copilot for unit tests?
Like in every other profession, there are tasks that we developers love to perform, and others that we don't really feel like doing. Scaffolding a new application is one of these examples, it's a lot of work to start a new project and get it to a point where you can finally be creative. Similarly, writing unit tests can be quite a repetitive task and finding motivation can be difficult. A good unit test should test one specific feature of the code. So, to provide a good coverage, you're going to need a lot of test methods and test classes.
Generative AI is a good tool to perform these repetitive tasks. In the video above, Gwyn shows that being very specific in the prompt will help create very specific test code, which is exactly what we need.
More information
You can learn more about the importance of unit tests, and how to write and run them in Visual Studio in this article.
We published a collection with resources here, and I am updating this with new resources as I discover them. In this collection, you can also explore the previous posts and videos in this series. All the videos referenced are published on the Visual Studio YouTube channel.