-
Notifications
You must be signed in to change notification settings - Fork 41
How to create test projects
This article describes how to create a new unit test project that will be run as part of build. The two important artifacts you need to create, are a project.json file and a global.json file.
Create a new test project under test/. The project.json should look similar to the following.
{
"dependencies": {
"Xunit.KRunner": "0.1-alpha-*",
"xunit.abstractions": "2.0.0-aspnet-*",
"xunit.assert": "2.0.0-aspnet-*",
"xunit.core": "2.0.0-aspnet-*",
"xunit.execution": "2.0.0-aspnet-*"
},
"configurations": {
"k10": {
"dependencies": {
"System.Runtime": "4.0.20.0"
}
},
"net45": {
"dependencies": {
"System.Runtime": ""
}
}
},
"commands": {
"test": "Xunit.KRunner"
}
}There are two things to note. First, we define the test command. This is the command that build runs during the test target. In our case, we use the xUnit.net Project K runner. Second, we reference both the xUnit.net libraries and the runner.
Since the projects we're testing are under src/ and not test/, we need to add a global.json file. This file tells Project K where to find additional sources. It should go in your repository's root and have the following contents.
{
"sources": ["src"]
}With these files in place, we are now be able to run tests. There are several ways to do this.
When you run build.cmd, all the test in your repository are run.
If you have installed the latest version of the xUnit.net runner for Visual Studio 2012 and 2013, you can run net45 tests using the built-in testing tools.
As an alternative to using the built-in tools, you can also use TestDriven.Net to run net45 tests.
To run individual test projects, run k test in the project's directory. For example:
CD test/MyProject.Tests
k testBy default, this will run the net45 configuration. To change this, set TARGET_FRAMEWORK.
SET TARGET_FRAMEWORK=k10
k test