2015 Ignite New Zealand demo prep: Step 4


  1. Intro
  2. VSO
  3. Docker
  4. xUnit
  5. Build
  6. Back end
  7. Selenium
  8. Docker
  9. Release Management
  10. Testing

Using Marcel’s post as my guide, I added xUnit tests to my demo.

  1. Add a Class Library (Package) project
    1. Right-click the src folder
    2. Select Add / New Project
    3. Select Class Library (Package)
    4. Enter name PeopleTracker.Preview.Tests
    5. Click OK
  2. Add Xunit and Xunit.Runner.Dnx packages
    1. Right-click the test project
    2. Select Manage NuGet Packages...
    3. Check the Include prerelease check box
    4. Search for Xunit.Runnder.Dnx
    5. Click Install
    6. Search for Xnuit
    7. Click Install
  3. Add a test command in the project.json
    1. Open project.json
    2. Copy and paste this code below the dependencies section

      "commands" : {
      "test": "xunit.runner.dnx -xml test-results.xml"

    Now, we need to add a reference to the ASP.NET application in our new class library. This will provide access to the classes in the ASP.NET so we can test them from our class library.

  4. Add reference in PeopleTracker.Preview.Tests to PeopleTracker.Preview
    1. Right-click on the References folder of class library
    2. Select Add Reference...
    3. Under the Projects section, select Solution
    4. Check the box next to your ASP.NET project
    5. Click OK
  5. Add unit test
    1. Right-click Class1.cs
    2. Select Rename
    3. Enter HomeControllerTests and press Enter
    4. Click Yes
    5. Replace the contents of the file with the code below

      using Xunit;

      namespace PeopleTracker.Preview.Tests
      public class HomeControllerTests
      public void Index()
      // Arrange
      var target = new PreviewWeb.Controllers.HomeController();

      // Act
      var results = target.Index();

      // Assert

    With this test in place, you can now execute it from Test Explorer.

  6. Commit and Push your changes
    1. Open Team Explorer
    2. Open Changes
    3. Enter comment
    4. Select Commit and Push

In the next post we will configure our build.

Pingbacks and trackbacks (24)+

Add comment