Skip to content
This repository was archived by the owner on Sep 25, 2026. It is now read-only.

Improve analyzer test infra to split linker tests into separate test cases in the TestExplorer - #2337

Merged
tlakollo merged 6 commits into
dotnet:release/6.0.2xxfrom
vitek-karas:ImproveAnalyzerTests
Oct 28, 2021
Merged

tlakollo merged 6 commits into
dotnet:release/6.0.2xxfrom
vitek-karas:ImproveAnalyzerTests

Conversation

@vitek-karas

Copy link
Copy Markdown
Member

xUnit will not split the test cases if the parameters to the Theory are complex objects. But if the parameter is a single string it will do it. So using a trick to store a string->object mapping and identify the tests by the string. When the test is executed the object representation is looked up from the string and executed.

It's not perfect, since xUnit doesn't have the same capability as NUnit to fully customize the generated test case name, so the tests show up as (for example):
RequiresCapability(m: "RequiresCapability.TestMethod")

But at least this allows running one test case in isolation.

As a followup, we should split the large tests cases into multiple files. RequiresCapability is the first obvious candidate as it has >1500 lines and currently generates 134 test cases for the analyzer. In general the tests should be refactored and split into more files:

  • Reasonably small file size and complexity - this helps with debugging, both linker and analyzer will run the product on the entire test file, and so if it has many methods and so on, debugging gets rather tedious.
  • Better isolation - we're already doing this by creating lot of subclasses which are used to isolate assets for each test (methods, types, ...). Unfortunately we took this too far, the RequiresCapability tests have 3 levels deep nesting currently.
  • Easier to navigate - Should be easier to find existing tests
  • More test cases in the linker tests - each file is treated as a separate test case for the linker, currently if something fails in RequiresCapability, it's just a single test failure - even if internally it is actually many different failures.

…cases in the TestExplorer

xUnit will not split the test cases if the parameters to the Theory are complex objects. But if the parameter is a single string it will do it. So using a trick to store a string->object mapping and identify the tests by the string. When the test is executed the object representation is looked up from the string and executed.

@sbomer sbomer left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice, thank you!

Had to add ProducedBy to LogContains attribute to handle the static ctor case.
@tlakollo
tlakollo merged commit f74fcd2 into dotnet:release/6.0.2xx Oct 28, 2021
@vitek-karas
vitek-karas deleted the ImproveAnalyzerTests branch October 29, 2021 18:42
@vitek-karas

Copy link
Copy Markdown
Member Author

Thanks a lot @tlakollo and @sbomer for finishing this!

agocke pushed a commit to dotnet/runtime that referenced this pull request Nov 16, 2022
…cases in the TestExplorer (dotnet/linker#2337)

* Improve analyzer test infra to split linker tests into separate test cases in the TestExplorer
xUnit will not split the test cases if the parameters to the Theory are complex objects. But if the parameter is a single string it will do it. So using a trick to store a string->object mapping and identify the tests by the string. When the test is executed the object representation is looked up from the string and executed.
* Add ProducedBy to LogContains attribute to handle the static ctor warning discrepancies between linker and analyzer
* Remove analyzer specific information in RunTest since now we run all analyzers at the same time

Commit migrated from dotnet/linker@f74fcd2
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants