Enable internal testclass discovery #944
Merged
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
It's useful to extract sets of test methods which establish some common criteria into reusable, generic, abstract test classes from which concrete test classes for specific types can be derived.
However, this technique requires that the type under test be as accessible as the test class, itself. In particular, it's a compile-time error to have a public class derived from a generic class parameterized with an internal type. So, either the type must be made public or the test class must be made internal, in order for the compiler to be satisfied.
Before the change in this PR, the test framework would only discover tests which were declared in public classes. This meant that the option of declaring the test class internal wasn't really an option at all: doing so would prevent the tests from running. So, types which should have been internal were marked public, just so they could be tested.
The following code reiterates the dilemma. After this commit, the tests in the
FancyStringsAreCaseInsensitive
class will be discovered.FancyStringTets.cs
FancyString.cs
CaseInsensitivityTests.cs
This test establishes support for the principal motivating scenario for the discovery of internal test classes.
This commit renames DiscoverInternalTestClassesAttribute to DiscoverInternalsAttribute, and causes the presence of that attribute in the assembly to additionally discover test methods which are declared internal, in addition to test methods which are declared public.
Co-authored-by: nohwnd me@jakubjares.com
Co-authored-by: Medeni Baykal 433724+Haplois@users.noreply.github.com