3
votes

I am merely a beginner and still trying to learn about TFS and its continuous integration workflow. Having that said, this could as well be a stupid question to ask as I might be missing on a simple detail, though any help or advice would be highly appreciated.

So, I have a fairly simple Unit Test example written using .NET Core 2.0, which I would like to run as a test task on our TFS Server's CI Build pipeline. It pretty much looks something like this:

using Microsoft.VisualStudio.TestTools.UnitTesting;

namespace MyUnitTest
{

    [TestClass]
    public class MyUnitTest
    {

        [TestMethod]
        public void PassingTest()
        {
            Assert.AreEqual(4, Add(2, 2));
        }

        [TestMethod]
        public void FailingTest()
        {
            Assert.AreEqual(5, Add(2, 2));
        }

        int Add(int x, int y)
        {
        return x + y;
        }

    }

}

When I try to run these tests in Visual Studio, it builds perfectly and the tests succeed and fail accordingly. So I commit my project and push it to our TFS git repository. Now, I similarly would like to integrate these tests in our build pipeline.

The Build Definition used in our CI builds looks like this. I have added Visual Studio Test - testAssemblies task in the build pipeline and configured the search pattern to find the assembly named MyUnitTest.dll and such. When I queue the build, I get the following warning in VSTest's log.

Warning: No test is available in C:\BuildAgent\_work\9\s\MyUnitTest\MyUnitTest\bin\release\netcoreapp1.1\MyUnitTest.dll. Make sure that installed test discoverers & executors, platform & framework version settings are appropriate and try again.

So, it seems to me that VSTest somehow cannot find tests to run in the target assembly. I am pretty positive that I might have misconfigured something, or forgotten to set some particular parameter appropriately. I will be more than grateful for any suggestion that would possibly pinpoint what I might be doing wrong.

Searching for solutions online, I have come across this question, which seems to have a similar problem.

1
Have you added the xUnit test runner NuGet package to your project?Wouter de Kort
Yes I have included xUnit test runner.Emre Akı
@EmreAKI this question has a similar problem, maybe its answer helps you tooSzeki
Which version of TFS are you using ?PatrickLu-MSFT

1 Answers

3
votes

First make sure your build agent environment is as same as your local develop machine. Such as Visual Studio version, MsTestAdapter ,xunit runner version and so on.

You could double confirm this by manually run the test directly on the build agent machine not through TFS.

Then use the below tasks in your build pipeline:

  1. Add a dotnet restore task.
  2. Then a dotnet build task.
  3. Add a dotnet test task with the arguments --no-build --logger "trx;LogFileName=tests-log.trx
  4. Add a Publish test results task with the following settings

enter image description here

More details please refer this tutorial blog: Running dotnet core xUnit tests on Visual Studio Team Services (VSTS)