Support for composable/extensible test context#6
Open
bkoelman wants to merge 2 commits into
Open
Conversation
|
Hi @bkoelman I know it's a very long time since this PR was reported. RoslynNUnitLight is in the process of deprecating and the recommended successor is https://github.com/cezarypiatek/RoslynTestKit - this is a newer version of RoslynNUnitLight. Your problem was solved in RoslynTestKit - if you need to test CodeFix that fixes an issue reported by given/provided |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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: