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

Inconsistency among NUnit2045 "Call independent Assert statements..." vs. NUnit documentation that does not require "independent" #732

Open
maettu-this opened this issue Apr 21, 2024 · 0 comments

Comments

@maettu-this
Copy link
Contributor

Consider this piece of test code where rate = new Rate(interval, window):

Assert.That(rate.Update(10), Is.True);
Assert.That(rate.Value, Is.EqualTo(13));

Assert.That(rate.Update(10), Is.True);
Assert.That(rate.Value, Is.EqualTo(27));

The analyzer (version 3.10 with NUnit 3.14.0) issues "warning NUnit2045: Call independent Assert statements from inside an Assert.Multiple". This statement is not fully correct,...

Notes:

  • The Update() method calculates Value and returns true if Value has changed.
  • Rewriting the test using Assert.Multiple() passes:
Assert.Multiple(() =>
{
	Assert.That(rate.Update(10), Is.True);
	Assert.That(rate.Value, Is.EqualTo(13));
});
Assert.Multiple(() =>
{
	Assert.That(rate.Update(10), Is.True);
	Assert.That(rate.Value, Is.EqualTo(27));
});

Potential solutions:

  • Remove the "independent" from message and documentation.
  • Clarify the intention and constraints of Assert.Multiple() with the NUnit team.
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

1 participant