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

false-positive xUnit1039 errors for tuples with mismatching member names. #2873

Closed
BrunoJuchli opened this issue Jan 26, 2024 · 3 comments
Closed

Comments

@BrunoJuchli
Copy link

When using tuples as test-method input and the tuple member names don't match, MemberDataShouldReferenceValidMember generates type-mismatch errors like:

error xUnit1039: The type argument (System.DateTime a, System.DateTime b) from TestClass.Data is not compatible with the type of the corresponding test method parameter _

I consider this a false-positive because even when the member names don't match, the tests will still run correctly.

If the current behavior is deemed as desired, I would however recommend to improve the error message. Ideally the message could tell me, that the type matches but the tuple member names don't.

Examples

TheoryData<> does not define names for tuple members, but Test methods does

.. or vice versa.

using System.Collections.Generic;
using Xunit;

public class TestClass {
    public static TheoryData<(int, int)> Data;

    [MemberData(nameof(Data))]
    public void TestMethod((int a, int b) _) { }
}

TheoryData<> defines a different name than test method

using System.Collections.Generic;
using Xunit;

public class TestClass {
    public static TheoryData<(int a, int b)> Data;

    [MemberData(nameof(Data))]
    public void TestMethod((int a, int iUseAnotherNameHereWhichIMakeExtraLongToBeObvoius) _) { }
}

This Works

When the tuple member names match, there's no error:

using System.Collections.Generic;
using Xunit;

public class TestClass {
    public static TheoryData<(int a, int b)> Data;

    [MemberData(nameof(Data))]
    public void TestMethod((int a, int b) _) { }
}
@JamesTerwilliger
Copy link
Contributor

On it

JamesTerwilliger pushed a commit to JamesTerwilliger/xunit.analyzers that referenced this issue Jan 26, 2024
@JamesTerwilliger
Copy link
Contributor

bradwilson pushed a commit to xunit/xunit.analyzers that referenced this issue Jan 28, 2024
@bradwilson
Copy link
Member

Available in 1.11.0-pre.6 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

No branches or pull requests

3 participants