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

New diagnostic: Remove a common parameter from TestCases #763

Open
Bartleby2718 opened this issue Jun 18, 2024 · 2 comments
Open

New diagnostic: Remove a common parameter from TestCases #763

Bartleby2718 opened this issue Jun 18, 2024 · 2 comments

Comments

@Bartleby2718
Copy link
Contributor

Bartleby2718 commented Jun 18, 2024

Another pet peeve of mine.

[TestCase(1, 42)]
[TestCase(2, 42)]
public void Example(int value1, int value2)
{
    Assert.That(value1, Is.LessThan(value2));
}

can be simplified to

[TestCase(1)]
[TestCase(2)]
public void Example(int value1)
{
    Assert.That(value1, Is.LessThan(42));
}

This reduces an unnecessary variable, helping you focus on what's important. (If you don't want a literal, you can use a const as opposed to a variable.)

@manfred-brands
Copy link
Member

Not sure I like this one.
The first allows adding a TestCase(3,4).
Once refactored with this CodeFix that is no longer possible.

@Bartleby2718
Copy link
Contributor Author

@manfred-brands Sure, but once you've added all test cases, would you still want a common parameter?

The idea of the proposed diagnostic is basically the same as Remove unused parameter (IDE0060). This may be annoying during development (as are many other style rules that are enabled in this repository), but once you're done writing tests, this diagnostic should help improve the readability of the code.

Let me know what you think!

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

2 participants