ci-logoThis is part of a series of walk throughs exploring CI in TFS, starting from the ground up. The entire series and source code are maintained at this BitBucket repository.
https://bitbucket.org/bladewolf55/tfs-ci-samples

Bonus: Uninstall!

Here's how to uninstall TFS, if necessary.

  1. Open Windows Services.
  2. Stop the VSO Agent service(s).
  3. Copy the service name(s).
  4. Delete the service from admin command prompt: sc delete vsoagent.Nesbit.Agent-Nesbit
  5. Open SQL Management Studio or Visual Studio SQL Server Object Explorer.
  6. Delete the Tfs databases.
  7. Open Programs and Features.
  8. Select Team Foundation Server Express 2015, choose Change, then Uninstall.

Install

Requirements and compatibility

Note These instructions are for TFS 2015 Update 3

 

Note about Visual Studio and MS Build Technically, you don't need to install Visual Studio to build using TFS. But, practically, you do, certainly if you use the recommended Visual Studio task. If you want to stick with just MS Build, you might be able to get away with installing the  2015 Build Tools

 

This walkthrough installs TFS, a build agent, and Visual Studio on one machine to keep the demonstration easy.

  1. Download latest version (2015 Update 3 as of this writing). ISO

  2. If you're using SQL 2016, Download and install the C++ Runtime prerequisite. http://support.microsoft.com/kb/3138367

  3. Run installer
    2017-01-27_142237

    2017-01-27_142348

  4. After installation, the Configuration Center opens. Select Basic Server and click Start Wizard.

    2017-01-27_143404

  5. Choose whether to participate in the Visual Studio Experience Improvement Program and click Next.
    2017-01-27_143548

  6. Choose whether to install SQL Express or use an existing instance. In my case, I already have SQL 2016 Express installed. Click Next.
    2017-01-27_143631

  7. The default SQL instance is displayed, or enter a named instance. This is the instance in which the TFS databases will be created. Click Next.
    2017-01-27_143755

  8. The next screen is what threw me. "Install and configure a build and deployment agent" is unchecked by default. You can install an agent later (I show how), but it's just as easy to install one now. Check the box and accept the defaults. Note the installation folder for later use. Click Next.

    2017-01-27_144005
    2017-01-27_144159

  9. Click Next again at the review screen.
    2017-01-27_144341

  10. Readiness checks will run. If something fails, you'll need to fix it before continuing, then click "Click here to rerun Readiness Checks. Once everything passes, click Configure.
    2017-01-27_144511

  11. TFS and the agent will be configured. This creates databases, the agent service, and the website. When complete, click Next.
    2017-01-27_144541

  12. Note the web site location. It's a good idea to open the web site now. Click Close.
    2017-01-27_150639

  13. You're done with the wizard, so click Close. This will open the Server Administration Console.
    2017-01-27_150745

  14. Select Build and Release. This page has some instructions. You can go directly to the TFS Settings > Agent page by click on Download Build and Deployment Agent. (Note: We will not be using the legacy XAML Build Configuration.). You can also get to the Settings page via the gear icon on the TFS web page.

    2017-01-27_151017

    2017-01-27_151136
    2017-01-27_151306
    2017-01-27_151349

Console App with Tests

  1. Create a Console application
     2017-01-30_104608
  2. Add two Class Library projects to the solution. We'll show consuming different test frameworks.
    CIConsoleSample.MSTests
    CIConsoleSample.xUnitTests
     2017-01-30_105018
  3. In the MSTests class library, add an Extensions reference to Microsoft.VisualStudio.QualityTools.UnitTestFramework
    2017-01-30_105737
    Also add a reference to the CIConsoleSample project.
     2017-01-30_111716
  4. In the xUnitTests class library, add the xUnit NuGet package, and the xunit.runner.visualstudio package.
    2017-01-30_113117
    And, as above, add the reference to the CIConsoleSample project.

Create MSUnit Tests

Rename Class1.cs to CIConsoleSampleMSTests, add the needed using statement and the following tests code. These tests use nested classes and a Class.Method_Should.Function naming style.

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
//Added for tests
using Microsoft.VisualStudio.TestTools.UnitTesting;

namespace CIConsoleSample.MSTests
{
    [TestClass]
    public class CIConsoleSampleMSTests
    {
        [TestClass]
        public class TextMan_Greeter_Should {
            [TestMethod]
            public void AppendTextToTheGreeting()
            {
                //arrange
                string value = "Charles";
                string expectedResult = "Hello, Charles";
                TextMan textMan = new TextMan();
                //act
                string actualResult = textMan.Greeter(value);
                //assert
                Assert.AreEqual(expectedResult, actualResult);
            }
        }
    }
}

Create xUnit Tests

Reference: https://xunit.github.io/docs/getting-started-desktop.html
Add a class file named CIConsoleSamplexUnitTests.cs, then the following code. As above, these tests use nested classes and a Class.Method_Should.Function naming style.

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
//added for tests
using Xunit;

namespace CIConsoleSample.xUnitTests
{
    public class CIConsoleSamplexUnitTests
    {
        public class TextMan_Greeter_Should
        {
            [Fact]
            public void AppendTextToTheGreeting()
            {
                //arrange
                string value = "Charles";
                string expectedResult = "Hello, Charles";
                TextMan textMan = new TextMan();
                //act
                string actualResult = textMan.Greeter(value);
                //assert
                Assert.Equal(expectedResult, actualResult);
            }
        }
    }
}

Run Failing Tests

First, here's how I like to display my tests, taking advantage of the nested class structure.

  • Tear off the Test Explorer into its own window, so that you can easily resize and see all the tests.
    test-tearoff
  • Group the test results by class
    test-byclass
  • In your xUnitTests project, add an app.config file with the following setting. This causes the result to display only the method name instead of the fully qualified name.
    <?xml version="1.0" encoding="utf-8" ?>
    <configuration>
      <appSettings>
        <add key="xunit.methodDisplay" value="method"/>
      </appSettings>
    </configuration>
  1. Build the solution so the tests are displayed in the runner.
     2017-01-30_120234
  2. Run the tests. They should both fail.
     2017-01-30_120353

This is enough for the moment. Let's add this solution to TFS, then to our CI server.

Add Solution to TFS

References
Create a team project Choose a process
Open the Team Explorer. If this is the first time connecting to TFS, you may see something like this (including the commercial).
2017-01-30_145139
Close the commercial, if you want, drop down Manage Connections and choose Connect to Team Project.
2017-01-30_145415
Select your local server. It will search for collections. Click Connect.
2017-01-30_145611
For this walk through, we're using TFS workspaces, not Git, for version control.
You can click "Configure your workspace" in the big mustard prompt. Or, click Project > Configure Workspace
2017-01-30_145755
The dialog maps the remote collection's root folder to a folder on your local computer. You can accept the default (which I'll do for this example), or choose another folder (which I'd normally do). Click "Map and Get". This is our first solution, so there are none to get.
2017-01-30_150019
Switch to Solution Explorer, right-click the solution, and choose Add Solution to Source Control.
2017-01-30_150759
I got this error message.

Full Disclosure I don't like TFS. This is an example of why. So much ceremony! I know there's a good reason, but sometimes I just want to get to work.

2017-01-30_150946
Switch back to Team Explorer, and choose Home > Projects and My Teams > New Team Project.
2017-01-30_153823
Name your team project. Click Next.
2017-01-30_153932
Choose the Agile process. Click Next.
2017-01-30_154431
Choose Team Foundation Version Control. Click Next, then Finish.
2017-01-30_154535
2017-01-30_154613
Now switch to Solution Explorer and add the solution to the team project.
2017-01-30_154745
The solution files are added locally, but not yet committed (checked in) to the repository. Right-click the solution and choose Check In.
2017-01-30_155043
Enter a comment and click Check In.
2017-01-30_155135
2017-01-30_155242
Next Part: TFS Continuous Integration Walk Through Part 2 - Create an Automated Build