Skip to content
This repository was archived by the owner on Nov 9, 2018. It is now read-only.

How to create test projects

Brice Lambson edited this page Mar 12, 2014 · 14 revisions

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.

The project.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.

The global.json file

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"]
}

Running tests

With these files in place, we are now be able to run tests. There are several ways to do this.

During build

When you run build.cmd, all the test in your repository are run.

From Visual Studio

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.

Using TestDriven.Net

As an alternative to using the built-in tools, you can also use TestDriven.Net to run net45 tests.

Ad-hoc

To run individual test projects, run k test in the project's directory. For example:

CD test/MyProject.Tests
k test

By default, this will run the net45 configuration. To change this, set TARGET_FRAMEWORK.

SET TARGET_FRAMEWORK=k10
k test
Clone this wiki locally