Writing unit tests for a CodeFixProvider
In this section, we will show you how to write and execute unit tests for a CodeFixProvider
.
Getting ready
You will need to have created and opened an analyzer + code fixer project, say CSharpAnalyzers
in Visual Studio 2017. Refer to the recipe, Creating, debugging, and executing an analyzer project in Visual Studio, in Chapter 1, Writing Diagnostic Analyzers for guidance.
Note
Note that the template unit test project contains unit tests for both the DiagnosticAnalyzer
and CodeFixProvider
. This chapter deals with CodeFixProvider
testing only. Refer to the recipe, Writing unit tests for an analyzer project in Chapter 1, Writing Diagnostic Analyzers for diagnostic analyzer unit tests.
How to do it...
- Open
UnitTests.cs
in theCSharpAnalyzers.Test
project in the solution explorer to view the default unit tests created for the default symbol analyzer and code fix provider in the project (Type names should not contain lower case letters):

- Click on
Test
|Windows...