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

How to create test projects

David Fowler edited this page Mar 6, 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-*",
        "xunit2": "0.1-alpha-*",
        "xunit2.assert": "0.1-alpha-*"
    },
    "configurations": {
        "k10": {},
        "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 project we're testing is under src/ 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 two ways to do this.

During build

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

Ad-hoc

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

CD test/MyProject.Tests
k test

By default, this will run the net45 configuration. Change this by setting TARGET_FRAMEWORK.

SET TARGET_FRAMEWORK=k10

Clone this wiki locally