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

Re-add "legacy" Assert methods #4693

Open
MgSam opened this issue Apr 16, 2024 · 7 comments
Open

Re-add "legacy" Assert methods #4693

MgSam opened this issue Apr 16, 2024 · 7 comments

Comments

@MgSam
Copy link

MgSam commented Apr 16, 2024

I know this is going to be controversial. However, I strongly recommend re-adding the "legacy" Assert/CollectionAssert/StringAssert methods (eg, Assert.Equal).

I believe Assert.That is objectively worse in every respect. In pre 4.0 versions, when you type Assert and then a dot, you get Intelliense for all the possible overloads (Equals, LessThan, etc). They are simple and straightforward to use. You do not need to go look up documentation.

Assert.That is the complete opposite. You have to "know" that the second argument requires a magical "Is" or "Does" construct. If you want to do something more complex you may have to chain multiple extremely undiscoverable method calls like Is.Not.... You are basically required to implicitly understand lots of extra-linguistic constructs that NUnit has added.

I understand that some people find the "That" syntax more pleasant to read. But I think it is way more difficult to write, way less discoverable, and a huge downgrade in usability for this library.

The main reason I and others have continued to prefer NUnit over XUnit is the superior simplicity and usability. Removing the easily discoverable methods we've all known and loved for decade(s) is a huge mistake, IMHO.

@OsirisTerje
Copy link
Member

They are still there, just under a name ClassicAssert. And if you want that to use the Assert, you can actually change that yourself using an alias, ref Using global using aliases, either as a global alias in the GlobalUsings.cs file, or directly in the csproj file.

global using Assert = NUnit.Framework.Legacy.ClassicAssert;

or in the csproj

<Using Include="NUnit.Framework.Legacy.ClassicAssert" Alias="Assert" />

You can then still use the That syntax if you like, in some cases.

We have no intention of removing these, but I assume you have read that we can't evolve the classic asserts the way we can with the constraint aliases.

@MgSam
Copy link
Author

MgSam commented Apr 16, 2024

Why rename them though and break everyone who upgrades?

@OsirisTerje
Copy link
Member

OsirisTerje commented Apr 16, 2024

We had to move them into a separate project.
We also considered moving it into its own project, but that is now on ice. But splitting out all assertions, including constraints, into their own packages does have merit.
And when it is in its own project, we can't have the same class name.

If C# had allowed extension methods on static classes (which have been discussed for one, and also here ), we could have solved it that way.

Also, this is a version 4, it does come with breaking changes, and that's also why we have a Migration Guide.

@renemadsen
Copy link

renemadsen commented May 22, 2024

@OsirisTerje

Also, this is a version 4, it does come with breaking changes, and that's also why we have a Migration Guide.

According to the migration guide it states: "The analyzer code fix supports Batch Fixing:"

But how is that done and can it be done from cli?

I'm using Rider and can only do one line at a time, which is a problem, when you have 10k+ lines that needs to be converted to the new format.

@manfred-brands
Copy link
Member

manfred-brands commented May 22, 2024

Within Visual Studio you can apply a CodeFix to either a Document, a Project or a Solution.

An issue for Rider has been open for years.

It might be that dotnet format work on the command line, but I haven't tried it. See dotnet/roslyn#48561

@stevenaw
Copy link
Member

stevenaw commented May 22, 2024

@renemadsen
Are you on .NET6+ by chance? The link shared by @manfred-brands also includes a suggestion for something like this from CLI (though I have not tried it myself)

EDIT: Oops. I see the original comment had already been updated to reflect that

dotnet format analyzers --diagnostics=DIAG_ID_TO_FIX

@OsirisTerje
Copy link
Member

Perhaps this can fix these things for us: https://devblogs.microsoft.com/dotnet/dotnet-build-2024-announcements/#c-13 - Extension types.

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

5 participants