Currently in. The testing tools under the Net framework mainly include Nunit, built-in MSTest, and Xunit, and this article will briefly introduce how to use XUnit, a rising star in VS.
The minimum runtime supported by xunit is . NET 4.5.2, most of which are higher. Even if you can build a 4.0 class library, it will still work on at least .NET 4.5.2. Detailed links:https://github.com/xunit/xunit/issues/1817
First, I created a new .NET 4.5.2 console project with the name: itsvse-test, and the latest version of xunit is: 2.4.1, so the nuget command is as follows:
Each package is licensed to you by its owner. NuGet is not responsible for third-party packages and does not license them. Some packages may include dependencies that are subject to other licenses. Click on the package source (source) URL to determine any dependencies.
Package Manager console host version 4.7.0.5212
Type "get-help NuGet" to see all available NuGet commands.
PM> Install-Package xunit -Version 2.4.1
Attempts are being made to collect and target ". NETFramework, Version=v4.5.2" of the project "itsvse-test" about the package "xunit.2.4.1" It takes 2.1 sec to collect dependency information Trying to resolve the dependency of package "xunit.2.4.1" with DependencyBehavior as "Lowest" Parsing dependency information takes 0 ms Parsing operation to install package "xunit.2.4.1" Resolved operation to install package "xunit.2.4.1" Retrieve package "xunit 2.4.1" from "cnblogs" Retrieve package "xunit.abstractions 2.0.3" from "cnblogs" Retrieve package "xunit.analyzers 0.10.0" from "cnblogs" Retrieve package "xunit.assert 2.4.1" from "cnblogs" Retrieve package "xunit.core 2.4.1" from "cnblogs" Retrieve package "xunit.extensibility.core 2.4.1" from "cnblogs" Retrieve package "xunit.extensibility.execution 2.4.1" from "cnblogs" GEThttps://api.nuget.org/v3-flatcon ... 1/xunit.2.4.1.nupkg GEThttps://api.nuget.org/v3-flatcon ... actions.2.0.3.nupkg GEThttps://api.nuget.org/v3-flatcon ... it.core.2.4.1.nupkg GEThttps://api.nuget.org/v3-flatcon ... .assert.2.4.1.nupkg GEThttps://api.nuget.org/v3-flatcon ... ty.core.2.4.1.nupkg GEThttps://api.nuget.org/v3-flatcon ... ecution.2.4.1.nupkg GEThttps://api.nuget.org/v3-flatcon ... lyzers.0.10.0.nupkg OKhttps://api.nuget.org/v3-flatcon ... actions.2.0.3.nupkg116 ms OKhttps://api.nuget.org/v3-flatcon ... 1/xunit.2.4.1.nupkg117 ms Installing xunit.abstractions 2.0.3. Installing xunit 2.4.1. OKhttps://api.nuget.org/v3-flatcon ... it.core.2.4.1.nupkg151 ms Installing xunit.core 2.4.1. OKhttps://api.nuget.org/v3-flatcon ... .assert.2.4.1.nupkg167 ms Installing xunit.assert 2.4.1. OKhttps://api.nuget.org/v3-flatcon ... ty.core.2.4.1.nupkg221 ms Installing xunit.extensibility.core 2.4.1. OKhttps://api.nuget.org/v3-flatcon ... lyzers.0.10.0.nupkg200 ms Installing xunit.analyzers 0.10.0. OKhttps://api.nuget.org/v3-flatcon ... ecution.2.4.1.nupkg306 ms Installing xunit.extensibility.execution 2.4.1. Adding package "xunit.abstractions.2.0.3" to folder "C:\Users\itsvse_pc\Source\Repos\itsvse-test\packages" Package "xunit.abstractions.2.0.3" has been added to folder "C:\Users\itsvse_pc\Source\Repos\itsvse-test\packages" Added package "xunit.abstractions.2.0.3" to "packages.config" Successfully installed "xunit.abstractions 2.0.3" to itsvse-test Adding toolset only package "xunit.analyzers.0.10.0" to "itsvse-test" Adding package "xunit.analyzers.0.10.0" to folder "C:\Users\itsvse_pc\Source\Repos\itsvse-test\packages" Package "xunit.analyzers.0.10.0" has been added to the folder "C:\Users\itsvse_pc\Source\Repos\itsvse-test\packages" Added package "xunit.analyzers.0.10.0" to "packages.config" Script file "C:\Users\itsvse_pc\Source\Repos\itsvse-test\packages\xunit.analyzers.0.10.0\tools\install.ps1" "xunit.analyzers 0.10.0" has been successfully installed to itsvse-test Adding package "xunit.assert.2.4.1" to folder "C:\Users\itsvse_pc\Source\Repos\itsvse-test\packages" Package "xunit.assert.2.4.1" has been added to the folder "C:\Users\itsvse_pc\Source\Repos\itsvse-test\packages" Added package "xunit.assert.2.4.1" to "packages.config" "xunit.assert 2.4.1" has been successfully installed to itsvse-test Adding package "xunit.extensibility.core.2.4.1" to folder "C:\Users\itsvse_pc\Source\Repos\itsvse-test\packages" Package "xunit.extensibility.core.2.4.1" has been added to the folder "C:\Users\itsvse_pc\Source\Repos\itsvse-test\packages" Added package "xunit.extensibility.core.2.4.1" to "packages.config" "xunit.extensibility.core 2.4.1" has been successfully installed to itsvse-test Adding package "xunit.extensibility.execution.2.4.1" to folder "C:\Users\itsvse_pc\Source\Repos\itsvse-test\packages" Package "xunit.extensibility.execution.2.4.1" has been added to the folder "C:\Users\itsvse_pc\Source\Repos\itsvse-test\packages" Added package "xunit.extensibility.execution.2.4.1" to "packages.config" "xunit.extensibility.execution 2.4.1" has been successfully installed to itsvse-test Adding package "xunit.core.2.4.1" to folder "C:\Users\itsvse_pc\Source\Repos\itsvse-test\packages" Package "xunit.core.2.4.1" has been added to the folder "C:\Users\itsvse_pc\Source\Repos\itsvse-test\packages" Added package "xunit.core.2.4.1" to "packages.config" "xunit.core 2.4.1" has been successfully installed to itsvse-test Adding package "xunit.2.4.1" with only dependencies to project "itsvse-test". Package "xunit.2.4.1" is being added to the folder "C:\Users\itsvse_pc\Source\Repos\itsvse-test\packages" Package "xunit.2.4.1" has been added to the folder "C:\Users\itsvse_pc\Source\Repos\itsvse-test\packages" Package "xunit.2.4.1" has been added to "packages.config" "xunit 2.4.1" has been successfully installed to itsvse-test Nuget took 5.51 sec to execute Time Elapsed: 00:00:07.7781544 PM> Install the plug-in packages: xunit.runner.console (omitted in this article) and xunit.runner.visualstudio
where xUnit is the framework,And xunit.runner.visualstudio is the VS plugin package, so that we can easily debug in VS.Installing xunit.runner.console can also be debugged under CMDBut if only this is supported, I believe not many people will use this framework, after all, the way of typing commands seriously lowers the grade of Visual Studio, so I will not explain it here.
Here, we only install the xunit.runner.visualstudio plugin package, right-click on the project in Solution Explorer and select Manage NuGet Packages. Search for (and install) a package named xunit.runner.visualstudio:
Make sure the test browser is visible (go to the Test > window > Test Explorer). Every time a project is built, the runner discovers unit tests in the project. After a period of discovery, you should see a list of discovered tests:
Edit the Program file and change the following code:
Click the link in the Run All window and you should see the result update in the Test Explorer window when you run the test:
You can click on the failed test to view the failure message and stack trace. You can click on the stack trace line to go directly to the failed line of code.
(End)
|