要求生成以包含单元测试 VSTS



我有 1 个问题

我们在公司使用 VSTS。现在我想要求我的开发人员为每个项目编写单元测试

我的问题是:如果我可以在团队服务 Web 门户中构建以要求包含单元测试,并且如果项目没有任何单元测试 - 设置生成失败?

谢谢。

可以添加PowerShell 任务来检查生成项目是否包含单元测试。详细步骤如下:

在 VS 测试任务之后添加 PowerShell 任务,并通过时间线 REST API 获取 VS 测试生成日志。对于 TFS,其余 api 格式应为:

GET http://{tsserver}:8080/tfs/{collection}/{project}/_apis/build/builds/{buildId}/timeline?api-version=3.0

然后在日志中搜索VS测试任务,就可以按url获取详细的VS测试构建日志。如下面的例子,VS测试任务构建日志可以在http://wxv-xindo-12r2:8080/tfs/DefaultCollection/5dfb8b33-9949-4187-9d09-474c8fe87238/_apis/build/builds/1477/logs/5中找到。

{
"id": "c43e4f8f-3db9-4fdc-90c0-1153f165b9a9",
"parentId": "39d66172-979a-46e8-a04d-fe8e4e77da43",
"type": "Task",
"name": "Test Assemblies",
"startTime": "2018-05-25T02:31:11.177Z",
"finishTime": "2018-05-25T02:31:17.133Z",
"currentOperation": null,
"percentComplete": null,
"state": "completed",
"result": "succeeded",
"resultCode": null,
"changeId": 17,
"lastModified": "0001-01-01T00:00:00",
"workerName": "mypc",
"order": 5,
"details": null,
"errorCount": 0,
"warningCount": 2,
"url": null,
"log": {
"id": 5,
"type": "Container",
"url": "http://tfsserver:8080/tfs/DefaultCollection/5dfb8b33-9949-4187-9d09-474c8fe87238/_apis/build/builds/1477/logs/5"
},
"task": {
"id": "ef087383-ee5e-42c7-9a53-ab56c98420f9",
"name": "VSTest",
"version": "2.0.55"
},
"issues": [
{
"type": "warning",
"category": "General",
"message": "",
"data": {
"type": "warning",
"code": "002004"
}
},
{
"type": "warning",
"category": "General",
"message": "No test assemblies found matching the pattern: **\release\*test*.dll,!**\obj\**.",
"data": {
"type": "warning"
}
}
]
}

然后检查 VS 测试任务是否有警告:

[warning]No test assemblies found matching the pattern: '***test*.dll;-:**obj**'

如果 VS 测试生成日志包含上述警告,则 PowerShell 任务失败exit 1

最新更新