Reputation: 361
I've installed NUnit (4.0.1) and NUnit3Testadapter (4.5.0) as a NuGet Package in Visual Studio 22.
Wrote my test cases, but I'm getting errors that definitions are missing from the Assert class:
Error CS0117 'Assert' does not contain a definition for 'AreEqual'
Error CS0117 'Assert' does not contain a definition for 'IsNotEmpty'
Error CS0117 'Assert' does not contain a definition for 'IsTrue'
How can I resolve these?
Upvotes: 36
Views: 25072
Reputation: 156
As far as I have done so far with version 4.0.1 which is latest and looks something like this.
You can assert any kind of result using Assert.That()
Upvotes: 11
Reputation: 412
It's a breaking change of NUnit 4.0
Just follow the steps:
Convert using NUnit.Framework;
into both using NUnit.Framework;
using NUnit.Framework.Legacy;
Convert Assert
into ClassicAssert
.
Assert.AreEqual
into ClassicAssert.AreEqual
.Assert.True
into ClassicAssert.True
.IsTrue
, False
, IsFalse
, Greater
, Less
, ...Detailed information can be found at: https://docs.nunit.org/articles/nunit/release-notes/Nunit4.0-MigrationGuide.html
Upvotes: 20
Reputation: 1
It looks like there are some problems with latest releases of NUnit package. 4.1.0 by me also does not work. I have downgraded NUnit back to 3.13.3 and it all works with again with method AreEqual.
Upvotes: 0
Reputation: 3079
Yeah, after updating to newest version, ran into same problem.
If you don't want to use the new way of asserting, change your Assert.Something, to ClassicAssert.Something, like:
Assert.IsTrue(result);
to
ClassicAssert.IsTrue(result);
If you want to give new syntax a try, use Assert.That instead, like:
Assert.That(result);
For more information check the docs new, classic syntax.
Upvotes: 36