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

UTA_MultipleExpectedExceptionsOnTestMethod is unused #4331

Closed
Youssef1313 opened this issue Dec 13, 2024 · 2 comments · Fixed by #4358
Closed

UTA_MultipleExpectedExceptionsOnTestMethod is unused #4331

Youssef1313 opened this issue Dec 13, 2024 · 2 comments · Fixed by #4358

Comments

@Youssef1313
Copy link
Member

IMO, instead of using it and issue a warning at runtime, this could be switched to an analyzer.

@Youssef1313
Copy link
Member Author

Youssef1313 commented Dec 13, 2024

@Evangelink Thoughts? I'm also not sure "when" did the resource became unused.

Note that while the attribute's AllowMultiple is false (default), we may still need to issue some sort of warning here for the niche scenario of the user defining his own attribute. The following will compile today even though AllowMultiple is false.

    public class MyExpectedExceptionAttribute : ExpectedExceptionBaseAttribute
    {
        protected override void Verify(Exception exception) => throw new NotImplementedException();
    }

    [TestMethod]
    [ExpectedException(typeof(Exception))]
    [MyExpectedException]
    public void Test() { }

Or even:

[AttributeUsage(AttributeTargets.Method, AllowMultiple = true)]
public class MyExpectedExceptionAttribute : ExpectedExceptionBaseAttribute
{
    protected override void Verify(Exception exception) => throw new NotImplementedException();
}

[TestMethod]
[MyExpectedException]
[MyExpectedException]
public void Test() { }

@Youssef1313
Copy link
Member Author

The behavior of issuing a warning on multiple attributes regressed on #2839 which is quite recent.

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

Successfully merging a pull request may close this issue.

2 participants