-
Notifications
You must be signed in to change notification settings - Fork 4k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Source Generators: how to unit test? #44075
Comments
Yes, as of today, you can use GeneratorDriver in unit tests. There are some examples in our own tests here: http://sourceroslyn.io/#Microsoft.CodeAnalysis.CSharp.Semantic.UnitTests/SourceGeneration/GeneratorDriverTests.cs,114 This is an area we're actively working on, and expect to ship templates / shims etc to make it easier to work with in the future |
I've added a gist that shows the basics of setting up unit test for generators here: https://gist.github.com/chsienki/2955ed9336d7eb22bcb246840bfeb05c |
A bit offtopic: I tried creating a generator and it works correctly in [VS 16.7 preview 2] but doesn't with |
Any thoughts on allowing access to the added sources from If there is a way to do it, I couldn't see an obvious one. EDIT: I've decided i'm fine with just |
FWIW @davidwengier added a SG to Windows Forms and unit tests for it in dotnet/winforms#4043 |
Added Unit test instructions to the cookbook at https://github.com/dotnet/roslyn/blob/master/docs/features/source-generators.cookbook.md#unit-testing-of-generators |
I'm trying to quickly iterate on my generator by simply running it from a unit test and inspecting the output.
I was hoping I could just construct a
SourceGeneratorContext
with some fake compilation, additional files and so on, run it, and then inspect what it added to it.But that's not feasible given its internal constructor.
For now, I just added to my generator a method I call from tests instead:
The text was updated successfully, but these errors were encountered: