Support for composable/extensible test context #6
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
@DustinCampbell Here the pull request for my comment earlier. I left out the FluentAssertions parts. But all my other features are in here, because I'm using a quite different API. Putting all features in separate pull requests at this moment would case much duplication and painful merges later. Based on discussions around this pull request, I can update it and remove parts that may be added later in another form. At a later time, I'd like to add some extensibility points to plug a custom assertion framework. Consider this pull request an expression to the direction I'd like to take this.
A key difference is that testing a
CodeFixProvidercan only be done from the output of its associated analyzer. This makes it possible to transfer analyzer state throughDiagnostic.Properties, along with its reported span(s) and automatically test-apply all suggested fixes. Personally, as an analyzer developer, I am more interested in testing a working combination of Analyzer + FixProvider, rather than unittesting scenarios for a standalone FixProvider.So I have one base class,
AnalysisTestFixture, from which unittests derive. To run a test, an immutable context is passed in. It has Withers to supply additional information, such as extra references, filename etc.Lastly, I changed reporting of builtin compiler errors, which were discarded before. I found that valuable, as it revealed some broken tests I had written weeks ago. The assertion method is virtual, so can be overridden from unittest classes. Callback could also be moved into context, if desired.
As an example, I rewrote the template tests for a new Analyzer/FixProvider project to use my API: