Skip to content
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

Add doppelganger test to all analyzers #75

Open
MattKotsenas opened this issue Jun 9, 2024 · 0 comments
Open

Add doppelganger test to all analyzers #75

MattKotsenas opened this issue Jun 9, 2024 · 0 comments
Labels
housekeeping .NET Pull requests that update .net code triage

Comments

@MattKotsenas
Copy link
Collaborator

NoConstructorArgumentsForInterfaceMockAnalyzerTests has a doppleganger test to ensure that it doesn't flag a user's class that happens to also be named Mock<T>. We should:

  1. Expand this scenario to cover all analyzers (probably with extended TestData?)
  2. Ensure we cover all the entrypoints to Moq
rjmurillo pushed a commit that referenced this issue Jun 10, 2024
…lysis.Testing patterns (#76)

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).

1. Use helper classes instead of inheritance to make the tests more
flexible
2. Centralize test defaults in a new `Test` class rather than in a base
class
3. Add a set of global usings to the default test to simplify tests and
make test authoring easier
4. Use xUnit's data-driven test method to simplify test scenarios
- Allows for a matrix of tests, both in the global namespace (fixes #56)
and in a given namespace
- Makes test debugging a bit easier as there's only a single Moq call
asserted in each test
- Makes reasoning about the test a bit more difficult, as now there's
distance between the test clause and the setup
5. After the test refactoring, there were a few cases of clear
duplication; removed and verified code coverage numbers are the same

I tried to also create "doppelganger" tests in this PR, like in
`NoConstructorArgumentsForInterfaceMockAnalyzerTests` where a user
creates a `Mock<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.
@rjmurillo rjmurillo added this to the vNext milestone Jun 12, 2024
@rjmurillo rjmurillo added .NET Pull requests that update .net code triage labels Jun 24, 2024
@rjmurillo rjmurillo modified the milestones: 0.2.0, vNext Jun 25, 2024
@rjmurillo rjmurillo removed this from the v0.2.0 milestone Oct 8, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
housekeeping .NET Pull requests that update .net code triage
Projects
None yet
Development

No branches or pull requests

2 participants