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 analyzer and fixer for test classes nested in generic classes #159

Merged
merged 4 commits into from
Aug 16, 2023
Merged

Add analyzer and fixer for test classes nested in generic classes #159

merged 4 commits into from
Aug 16, 2023

Conversation

joaonunomota
Copy link
Contributor

Closes xunit/xunit#2528

Adds analyzer and fixer to prevent the error:
System.ArgumentException: Cannot create an instance of Tests+A'1+B[T] because Type.ContainsGenericParameters is true.

The analyzer includes a check for tests in the base classes if the derived class does not directly contain tests, and limits the search to a depth of 3 classes in case of circular dependencies.

@joaonunomota joaonunomota marked this pull request as draft August 16, 2023 12:12
@joaonunomota joaonunomota marked this pull request as ready for review August 16, 2023 13:36
@bradwilson
Copy link
Member

The current build failures are not caused by your PR (I have added another PR to verify this). I'm investigating to see if I can figure out what's going on.

@bradwilson
Copy link
Member

Looking like .NET SDK 7.0.400 is to blame, as it's bringing in a new version of dotnet test which is strangely a preview version:

Test run for /home/runner/work/xunit.analyzers/xunit.analyzers/src/xunit.analyzers.tests/bin/Release/net472/xunit.analyzers.tests.dll (.NETFramework,Version=v4.7.2)
Microsoft (R) Test Execution Command Line Tool Version 17.7.0-preview-23364-03+bc17bb9693cfc4778ded51aa0ab7f1065433f989 (x64)

I can reproduce it locally with that installed inside WSL. Using .NET SDK 6 instead of 7 seems to fix it. Just running a pass on my PR to verify.

@bradwilson
Copy link
Member

Opened a bug: microsoft/vstest#4657

@bradwilson bradwilson merged commit 34d10d5 into xunit:main Aug 16, 2023
5 checks passed
@bradwilson
Copy link
Member

Thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Exception when running tests in a nested class derived from a generic class who also is its parent
2 participants