Unit testing plays a significant role in assuring the quality of the applications we develop. To unit test an ASP.Net 5 RC1 Update1 (
ASP.Net Core 1.0 now), web application we can use xUnit.
To add xUnit test to the solution add a Class Library (Package) project.

Edit the default project.json shown below.

Add dependency to the ASP.Net 5 web project, and to xUnit and xUnit.Runner.Final project.json should be similar to below.
{
"version": "1.0.0-*",
"description": "BookMyEvents.UnitTests Class Library",
"authors": [ "Chaminda" ],
"tags": [ "" ],
"projectUrl": "",
"licenseUrl": "",
"dependencies": {
"BookMyEvents": "1.0.0-*",
"xunit": "2.1.0",
"xunit.runner.dnx": "2.1.0-rc1-build204"
},
"commands": {
"test": "xunit.runner.dnx"
},
"frameworks": {
"dnx451": { },
"dnxcore50": {}
}
}
Once the project.json saved the references get updated.

Let’s write a test for a very simple controller method.

Test method as a Fact (There are two types of Unit Tests in xUnit. Fact and Theory. More information
here).

Go to test explorer in VS to view the test.

If you cannot see test as above build your solution. Test will be then available in the explorer. Execute and you can see the results.

Next post let’s learn how to run the unit tests (xUnit), with VS Team Service build and publish test results.