The xUnit.net team tried to ensure that migration of unit tests from v1 to v2 would be as painless as possible. Most of the migration tasks should be fairly straightforward and mechanical (replacing NuGet packages, doing simple search & replace, etc.).
Steps:
Binaries for xUnit.net are now distributed exclusively through NuGet. Updating the binaries differs based on whether you originally used CodePlex or NuGet to acquire them. Please choose from one of the two options below.
You will need to manually remove any references to xunit.dll
and/or xunit.extensions.dll
.
Then, add the new xunit
NuGet package. Start by right clicking
on the project in Solution Explorer, and then choosing the
Manage NuGet Packages...
menu item:
Click on Browse
in the upper left corner. In the search box on the upper
right, type xunit
. The search should yield results like this:
Locate the xUnit.net entry, and click Install
.
Right click on the project in Solution Explorer, and then choose the
Manage NuGet Packages...
menu item:
Click on Installed
along the top. If you see
xUnit.net: Extensions
installed, please click the
Uninstall
button. (If NuGet offers to uninstall the
xunit
package for you, you should decline. You're going to
upgrade that package in the next step.)
Click on Updates
along the top. Locate xUnit.net
in the list of packages, and click Update
:
Build your solution. If everything compiles, then you're done!
If it doesn't compile, here are some of the things that may need to upgraded by hand:
Compiler error:
'Xunit.Extensions.PropertyDataAttribute' is obsolete: 'Please replace [PropertyData] with [MemberData]'
If you get this compiler error, change all instances of [PropertyData]
to [MemberData]
. The new MemberDataAttribute
class can read data from static properties (just like PropertyDataAttribute
),
but now also supports data from static fields and static methods. You can
even provide parameter values to static methods!
Compiler error:
'Xunit.FactAttribute' does not contain a definition for 'Timeout'
The support for tests that automatically time out has been removed from xUnit.net v2, and there is no direct replacement for this feature. The reason it was removed was that v2 is designed from the ground up to be async and parallel, and accurately timing tests in such a design is effectively impossible.
Compiler error:
The type or namespace name 'IUseFixture<T>' could not be found (are you missing a using directive or an assembly reference?)
The interface has been renamed, and its behavior is slightly different now.
IUseFixture
to IClassFixture
.SetFixture
method. If you need access to your fixture object, you can accept it as a constructor argument instead.
See Sharing Context between Tests for more information about IClassFixture
.
Missing classes from xunit.extensions
Please see
Migrating extensions from v1 to v2
for information on migrating code that used xunit.extensions
to xUnit.net v2.