Skip to content

Continue analyzing remaining MemberData attributes after reporting an error - #234

Merged
bradwilson merged 2 commits into
xunit:mainfrom
meziantou:feature/memberdata-analyzer-false-negatives-3d3ac0
Sep 16, 2026
Merged

bradwilson merged 2 commits into
xunit:mainfrom
meziantou:feature/memberdata-analyzer-false-negatives-3d3ac0

Conversation

@meziantou

Copy link
Copy Markdown
Contributor

Problem

MemberDataShouldReferenceValidMember loops over every [MemberData] attribute on a test method, but several error paths used return inside that loop instead of continue. After one attribute produced a diagnostic, the analyzer skipped all the remaining [MemberData] attributes on the method.

public class TestClass {
    public TheoryData<int> NonStatic => null;

    [Theory]
    [MemberData("Missing")]          // xUnit1015 reported
    [MemberData(nameof(NonStatic))]  // xUnit1017 was never reported
    public void Test(int _) { }
}

Fix

The five early exits in the attribute loop now continue instead of return:

  • xUnit1057: member type must be public or internal (AOT)
  • xUnit1068: member type is an open generic (AOT)
  • xUnit1015: member doesn't exist
  • xUnit1065: method is ambiguous
  • xUnit1018: member isn't a field, method or property

Tests

I added the repro to the existing X1015_MemberDataShouldReferenceValidMemberTests.V2_and_V3 test instead of creating a new test method. Without the fix, the test fails with expected "2" actual "1". All net8.0 tests pass.

meziantou and others added 2 commits September 13, 2026 21:32
… error

Several error paths in MemberDataShouldReferenceValidMember used 'return' inside
the attribute loop, so once one [MemberData] attribute produced a diagnostic, all
subsequent [MemberData] attributes on the same method were skipped.
@bradwilson
bradwilson merged commit 99a9a9d into xunit:main Sep 16, 2026
1 check passed
@bradwilson

Copy link
Copy Markdown
Member

Thanks!

@bradwilson

Copy link
Copy Markdown
Member

Available in 2.2.0-pre.16 https://xunit.net/docs/using-ci-builds

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.

2 participants