将Cake dotnet核心测试输出导出到TeamCity

时间:2017-01-30 23:58:08

标签: c# teamcity .net-core cakebuild

我正在寻找一种方法,通过Cake构建脚本将测试输出从.NET Core应用程序导出到TeamCity。

目前,我只是在运行:

year = input("Enter the year for the data you want to receive:")
with open("students.txt") as f:
    # read stripped file lines into list keeping only those that contain data
    data = [line.strip() for line in f.readlines() if line.strip() != '']
# build a dict from the data using list slicing to get the years (keys) and heights (values)
data_dict = dict(zip(data[0::2], data[1::2]))
# print the heights if the year exists otherwise 'No data.'
print(data_dict.get(str(year)) if data_dict.get(str(year)) else 'No data.')

但我在ITeamCityProviderDotNetCoreTest

的文档中看不到任何内容

上面的代码块可以从命令行运行,但我找不到将测试结果发布到构建服务器的方法。

希望有人可以提供帮助

2 个答案:

答案 0 :(得分:4)

使用NUnit test runner for .NET Core,您需要明确传递--teamcity选项,以便将测试结果报告给TeamCity(请参阅commit 323fb47)。

在Cake脚本中,您可以使用ArgumentCustomization属性

来实现
Task("Test")
   .Does(() =>
{
    DotNetCoreTest(
        "path/to/Project.Tests",
        new DotNetCoreTestSettings
        {
            ArgumentCustomization = args => args.Append("--teamcity")
        });
});

答案 1 :(得分:3)

在这种情况下再次发现自己在谷歌搜索,偶然发现我对其他答案的无用评论...

基本上,您在Cake中需要做的就是使用标准设置(并非TeamCity专用)调用DotNetCoreTest,并在测试项目中包括以下NuGet软件包:

  • TeamCity.Dotnet.Integration
  • TeamCity.VSTest.TestAdapter

我还在tools\modules\packages.config中配置了Cake构建系统模块:

<?xml version="1.0" encoding="utf-8"?>
<packages>
    <package id="Cake.BuildSystems.Module" version="0.3.0" />
</packages>

这将点亮TC中的“测试”标签。

相关问题