How to write automated tests
Writing automated tests for all your code gives you the confidence to change your code and know whether you broke anything. This applies to all code, including analyzers and code fixes. For anything that extends the compiler or provides editors or IDEs with new capabilities, it’s also harder to test whether or not your implementation works. It can be frustrating at times to get things working and can hamper your productivity by building these.
Luckily, Microsoft has provided an easy way to test your analyzers and code fixes:
- Next to the Roslyn.Extensions folder, create a folder called Roslyn.Extensions.Tests. In a terminal, navigate to the Roslyn.Extensions.Tests folder and run the following:
dotnet new xunit
The command will set up a test project using the xUnit (https://xunit.net) testing library.
Important note
You can use other testing frameworks as well, such as MSTest or NUnit.
We will not cover unit testing or the...