-
Notifications
You must be signed in to change notification settings - Fork 2
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
Refactor unit tests: data driven tests and leverage Microsoft.CodeAnalysis.Testing patterns #76
Conversation
This generally looks good. Some new warnings in the build log (and when I run locally). Example: https://github.com/rjmurillo/moq.analyzers/actions/runs/9443378573/job/26007024628#step:7:52
xUnit believes they are the same test, but it's actually two separate tests for different analyzers. You want to live with this for now and see if the uber combined test is enough? |
Thanks for flagging the duplicate test thing. I don't understand what's happening there, so will dig in. Edit: These are all legit duplicated test cases that I removed. Following the trail backwards, there were some old tests that had cases like: var mock1 = new Mock<Foo>();
var mock2 = new Mock<FullyQualifiedNamespace.Foo>() In my other refactorings these got simplified to var mock1 = new Mock<Foo>();
var mock2 = new Mock<Foo>(); which when turned into test-driven tests xUnit can flag as duplicates. I went back and verified that code coverage metrics don't meaningfully change (slightly complicated by the warning refactor, but withing 4 lines of before). So I think this is good to do, doesn't regress code coverage, etc. |
After the switch to using
Microsoft.CodeAnalysis.Testing
, refactor the tests to better follow the test infrastructure conventions. (For additional examples, check out the dotnet/roslyn-analyzers repo).Test
class rather than in a base classI tried to also create "doppelganger" tests in this PR, like in
NoConstructorArgumentsForInterfaceMockAnalyzerTests
where a user creates aMock<T>
class in the namespace to make sure the analyzers are doing fully-qualified name resolution. However, to do that generically requires duplicating a lot of more of Moq's own API, and I'm not sure if that's a good idea, so filed #75 to track.There's probably more that can be done to DRY out the test templates, but I wanted to make sure this was a good step forward before going any further.