在TFS构建管道上运行(x)单元测试 [英] Running (x)Unit Tests on TFS Build Pipeline

查看:163
本文介绍了在TFS构建管道上运行(x)单元测试的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我只是一个初学者,仍在尝试了解TFS及其持续集成工作流程。话虽这么说,但这也可能是一个愚蠢的问题,因为我可能在一个简单的细节上可能会丢失,尽管任何帮助或建议都将受到高度赞赏。



所以,我有一个使用.NET Core 2.0编写的相当简单的单元测试示例,我想将其作为测试任务运行在TFS Server的CI Build管道上。看起来很像这样:

 使用Microsoft.VisualStudio.TestTools.UnitTesting; 

命名空间MyUnitTest
{

[TestClass]
公共类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;
}

}

}



<当我尝试在Visual Studio中运行这些测试时,它会完美构建,并且测试会相应地成功和失败。因此,我提交了项目并将其推送到我们的TFS git存储库。现在,我同样希望将这些测试集成到我们的构建管道中。



CI构建中使用的构建定义看起来像



更多详细信息,请参阅本教程博客:在Visual Studio上运行dotnet核心xUnit测试团队服务(VSTS)


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.

解决方案

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

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

这篇关于在TFS构建管道上运行(x)单元测试的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆