Back to Nunit

Breaking Changes

docs/articles/nunit/release-notes/breaking-changes.md

latest10.8 KB
Original Source

Breaking Changes

NUnit 4.0

See the Migration Guide for moving your tests from NUnit 3.x to NUnit 4.0 if you are using any of the following features:

  • The Classic Asserts have been moved to a separate library and their namespace and their class name were renamed to: NUnit.Framework.Legacy.ClassicAssert.
  • The standalone assert classes have also been moved to the NUnit.Framework.Legacy namespace. These classes are:
  • Assert.That overloads with format specification and params have been removed in favor of an overload using FormattableString.
  • The lowest framework version supported is now version 4.6.2 and .Net 6.0.

See full list of deprecated issues and breaking changes in the framework.

NUnit 3.10

  • NUnit.Framework.Constraints.NUnitEqualityComparer.Default was deprecated in favor of new NUnitEqualityComparer().

NUnit 3.8

  • Removed some deprecated attributes:

  • TestFixtureSetUpAttribute (use OneTimeSetUpAttribute)

  • TestFixtureTearDownAttribute (use OneTimeTearDownAttribute)

  • RequiresSTAAttribute (use ApartmentAttribute)

  • RequiresMTAAttribute (use ApartmentAttribute)

  • Removed deprecated Is.StringXxxx syntax elements:

  • Is.StringStarting (use Does.StartWith)

  • Is.StringEnding (use Does.EndWith)

  • Is.StringContaining (use Does.Contain)

  • Is.StringMatching (use Does.Match)

NUnit 3.7

  • The AssertionHelper class has now been deprecated. Users can use the NUnit.StaticExpect library as a near drop-in replacement.

NUnit 3.4

Breaking changes introduced in NUnit 3.4

  • The --teamcity console command-line option now requires the TeamCityEventListener extension to be installed. This only affects users who install the extensions individually or copy them to another directory. If you install using the Windows installer or the NUnit.Console NuGet package the TeamCity extension is included.

  • String arguments in the names of test cases are no longer truncated to 40 characters.

  • The .NET 2.0 build of the nunit framework uses a private implementation of System.Linq. NUnit installs the NUnit.System.Linq assembly alongside the nunit.framework assembly. If you copy the framework to another location, you must ensure that both are copied. The extra assembly is not used in other builds because System.Linq is already supported in those environments.

NUnit 3.0

A relatively large number of features present in NUnit 2.6, were either removed in NUnit 3.0 or had their behavior modified in a way that will break existing code.

A key change is that the NUnit Test Engine will not recognize a test assembly that does not reference the NUnit framework directly. Normally, test assemblies use NUnit Asserts, attributes and other Types and methods. However, certain third-party frameworks are designed to completely isolate the user from the details of NUnit. They mediate between the test assembly and the NUnit framework in order to run tests. In such a case, NUnit will indicate that the assembly either contains no tests or the proper driver could not be found. To resolve this situation, simply add one NUnit attribute or other reference. An assembly-level ParallelizableAttribute is useful for this purpose.

Other breaking changes are grouped in the following tables.

Attributes

NameNotes
ExpectedExceptionAttributeNo longer supported. Use Assert.Throws or Assert.That.
IgnoreAttributeThe reason is now mandatory
RequiredAddinAttributeNo longer supported.
RequiresMTAAttributeDeprecated. Use ApartmentAttribute
RequiresSTAAttributeDeprecated. Use ApartmentAttribute
SuiteAttributeNo longer supported.
System.MTAThreadAttributeNo longer treated as RequiresMTAAttribute
System.STAThreadAttributeNo longer treated as RequiresSTAAttribute
TearDown and OneTimeTearDownThere is a change to the logic by which teardown methods are called. See Setup and Teardown Changes for details.
TestCaseAttributeNamed parameter Result= is no longer supported. Use ExpectedResult=. Named parameter Ignore= now takes a string, giving the reason for ignoring the test.
TestCaseSourceAttributeThe attribute forms using a string argument to refer to the data source must now use only static fields, properties or methods.
TestFixtureAttributeNamed parameter Ignore= now takes a string, giving the reason for ignoring the test.
TestFixtureSetUpAttributeDeprecated. Use OneTimeSetUpAttribute.
TestFixtureTearDownAttributeDeprecated. Use OneTimeTearDownAttribute.
ValueSourceAttributeThe source name of the data source must now use only static fields, properties or methods.

Assertions and Constraints

FeatureNotes
Assert.IsNullOrEmptyNo longer supported. Use Assert.That(..., Is.Null.Or.Empty)
Assert.IsNotNullOrEmptyNo longer supported. Use Assert.That(..., Is.Not.Null.And.Not.Empty)
Is.InstanceOfTypeNo longer supported. Use Is.InstanceOf
Is.StringStartingDeprecated. Use Does.StartWith
Is.StringContainingDeprecated. Use Does.Contain
Is.StringEndingDeprecated. Use Does.EndWith
Is.StringMatchingDeprecated. Use Does.Match
NullOrEmptyStringConstraintNo longer supported. See Assert.IsNullOrEmpty above
Text.AllNo longer supported. Use Has.All or Is.All
Text.ContainsNo longer supported. Use Does.Contain or Contains.Substring
Text.DoesNotContainNo longer supported. Use Does.Not.Contain
Text.StartsWithNo longer supported. Use Does.StartWith
Text.DoesNotStartWithNo longer supported. Use Does.Not.StartWith
Text.EndsWithNo longer supported. Use Does.EndWith
Text.DoesNotEndWithNo longer supported. Use Does.Not.EndWith
Text.MatchesNo longer supported. Use Does.Match
Text.DoesNotMatchNo longer supported. Use Does.Not.Match

Other Framework Features

FeatureNotes
AddinsNo longer supported. See Addin Replacement in the Framework.
CurrentDirectoryNo longer set to the directory containing the test assembly. Use TestContext.CurrentContext.TestDirectory to locate that directory.
NUnitLiteNUnitLite executable tests must now reference nunit.framework in addition to NUnitLite.
SetUpFixtureNow uses OneTimeSetUpAttribute and OneTimeTearDownAttribute to designate higher-level setup and teardown methods. SetUpAttribute and TearDownAttribute are no longer allowed.
TestCaseDataThe Throws Named Property is no longer available. Use Assert.Throws or Assert.That in your test case.
TestCaseDataThe Categories Named Property is no longer available. Use Properties["Category"] instead.
TestContextThe fields available in the TestContext have changed, although the same information remains available as for NUnit V2.
Async void testsNo longer supported. Use async Task as the method signature instead.

Console Features

The console runner is now called nunit3-console. The following breaking changes apply to the options that the new runner supports.

OptionFunctionNotes
--fixture=STRTest fixture or namespace to be loadedNo longer supported. Use --test instead.
--run=STRList of tests to runNo longer supported. Replaced by --test.
--runlist=PATHFile containing list of tests to runNo longer supported. Replaced by --testlist.
--include=LISTList of categories to includeNo longer supported. Use --where instead.
--exclude=LISTList of categories to excludeNo longer supported. Use --where instead.
--process=PROCESSProcessModel for test assembliesDefault value is now Separate for a single assembly, Multiple for more than one. Multiple assemblies run in parallel by default.
--domain=DOMAINDomainUsage for test assembliesDefault value is now Separate for a single assembly, Multiple for more than one.
--apartment=APTApartment in which to run testsNo longer supported. Use ApartmentAttribute.
--xml=PATHOutput result xml to pathNo longer supported. Use --result=SPEC instead.
--noxmlDisable xml result outputNo longer supported. Use --noresult instead.
--xmlconsoleDisplay XML to the consoleNo longer supported.
--basepathSet ApplicationBase for executionNo longer supported.
--privatebinpathSpecify probing path for executionNo longer supported.
--cleanupRemove left-over cache filesNo longer supported.
--noshadowDisable shadow copyNo longer supported. The console runner now disables shadow copy by default. use --shadowcopy on the command-line to turn it on.
--nothreadDisable use of a separate thread for testsNo longer supported.
--nodotsDo not display dots as a progress indicatorNo longer supported.