How to create an xUnit test project
To create a new xUnit test project, you can run the dotnet new xunit command, and the CLI does the job for you by creating a project containing a UnitTest1 class. That command does the same as creating a new xUnit project from Visual Studio.For unit testing projects, name the project the same as the project you want to test and append .Tests to it. For example, MyProject would have a MyProject.Tests project associated with it. We explore more details in the Organizing your tests section below.The template already defines all the required NuGet packages, so you can start testing immediately after adding a reference to your project under test.
You can also add project references using the CLI with the
dotnet add referencecommand. Assuming we are in the./test/MyProject.Testsdirectory and the project file we want to reference is in the./src/MyProjectdirectory; we can execute the following command to add a reference:
dotnet add reference ../../src...