Don045
Don045

Reputation: 361

NUnit Assert is missing definitions

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

Answers (5)

MaxJimenez
MaxJimenez

Reputation: 1

Look at NUnit Docs

You can replace Assert with ClassicAssert

Upvotes: 0

sapana
sapana

Reputation: 156

As far as I have done so far with version 4.0.1 which is latest and looks something like this.

  1. Assert.That(result, Is.Not.Null);
  2. Assert.That(result, Is.Null);
  3. Assert.That(result, Is.EqualTo(something));
  4. Assert.That(result, Is.False);
  5. Assert.That(result, Is.True);

You can assert any kind of result using Assert.That()

Upvotes: 11

Morris Li
Morris Li

Reputation: 412

It's a breaking change of NUnit 4.0

Just follow the steps:

  1. Convert using NUnit.Framework; into both using NUnit.Framework; using NUnit.Framework.Legacy;

  2. Convert Assert into ClassicAssert.

    1. Convert Assert.AreEqual into ClassicAssert.AreEqual.
    2. Convert Assert.True into ClassicAssert.True.
    3. Similar for 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

Evgeniy Zakharov
Evgeniy Zakharov

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

Tafari
Tafari

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

Related Questions