This document discusses how to set up unit testing with xUnit and .NET Core using Visual Studio Code. It includes steps to:
1. Download and install the .NET SDK and Visual Studio Code.
2. Create a unit test project in Visual Studio Code and add the xUnit testing framework package via NuGet.
3. Write the first test and parametrized test, using xUnit's Fact and Theory attributes to test methods in the project.
4. Execute the tests directly from Visual Studio Code.
2. Hi All, In this my first article, I will explain getting started with xUnit open source testing framework and
.NET Core using open source code editor VSCode ,showing you how you can create and run your first
set of unit tests.
Hi All, In this my first article, I will explain getting started with xUnit open source
testing framework and .NET Core using open source code editor VSCode ,showing
you how you can create and run your first set of unit tests.
1. Download the .NET SDK
2. Download the Visual Studio Code
3. Add C# extension
4. Create the unit test project
5. Add xUnit testing framework package
6. Create first test
7. Create first Parametrized tests
8. Execute tests with Visual Studio Code using xUnit testing framework
3. Download and install the .NET SDK
• Go to https://dotnet.microsoft.com/download/dotnet-core/2.2
• Download the SDK based on your machine configuration. Here I am using x64 and window7.
1. Download and install the .NET SDK
4. 2. Download and install the VSCode using following
link https://code.visualstudio.com/
5. 3. Add the C#
extension
• Open the VSCode editor,
6. • Click Ctrl + Shift + X to open the Extension
search box to add the C# omni extension,
Search C# for visual and install it.
7. 4.Create the unit test
project
• Now type Ctrl+Shift+E to open the Project
explorer
8. • Now Click “Add Folder” and
create one folder
XUnitTestProject. Click the
“Add” to add this folder into the
workspace.
10. • Right click on the project XUnitTestProject add
new folder “src” then add another folder obj-
>objects inside it.
11. • Right click on Objects folder and
select the new file, add name
Class1.cs.
• Add following code in the class.
• In this class, two methods are to
return the sum of two numbers
and another method to check the
prime number.
12. • Now go to terminal and type following
command to build the project and it will
generate the project related files.
• Type “dotnet build” in the termial.
13. 5. Add xUnit testing
framework package • Type Ctrl+Shift+P to open the NuGet Package
Manager: Add Package
18. 6.Create first test
7.Create first Parametrized tests
• Now create another folder under the project
give the TestClass and create one test class
under this folder to write the unit test cases to
test the Class1
19. • Here we are using the power
of xUnit, FACT and Theory:
• FACT is used for individual
test.
• Theory is used for
parameterized tests.
• Fact is being used with
testAdd method and Theory
with testPrime method.
20. 9.Execute tests with Visual Studio
Code using xUnit testing framework
• Now go to TestClass, click the Run All Tests.