启动屏幕上的TFS代码覆盖率?

时间:2016-10-02 20:11:14

标签: tfs code-coverage tfs2015

在TFS中,可以在开始屏幕上获取构建历史数据。因此,当您登录TFS时,您会立即看到构建的状态。显示代码覆盖率可以达到同样的效果吗?这是SonarCube绝对做得很好的事情。

1 个答案:

答案 0 :(得分:0)

在开始屏幕中没有包含代码覆盖率结果的功能。但您可custom dashboard widget test REST API来实现这一目标。

自定义信息中心的简单示例:

<!DOCTYPE html>
<html>
<head>
    <title>Custom widget</title>
    <meta charset="utf-8" />
    <script src="node_modules/vss-web-extension-sdk/lib/VSS.SDK.js"></script>
    <script type="text/javascript">
        VSS.init({
            explicitNotifyLoaded: true,
            usePlatformStyles:true
        });
        VSS.require(["TFS/Dashboards/WidgetHelpers","TFS/TestManagement/RestClient"], function (WidgetHelpers,TFS_Test_WebApi) {
            WidgetHelpers.IncludeWidgetStyles();
            VSS.register("WidgetStarain", function () {

                var projectId = VSS.getWebContext().project.id;
                var getCodeCoverage = function (widgetSettings) {
                    return TFS_Test_WebApi.getClient().getBuildCodeCoverage(projectId, 252)
                           .then(function (buildCoverage) {
                               var $codeCoverageResult = $('div.codeCoverage');
                               var $codeCoverageObject = buildCoverage.coverageData[0].coverageStats;
                               var $detailResult = $codeCoverageObject[0].label + ": Total:" + $codeCoverageObject[0].total + ";covered:" + $codeCoverageObject[0].covered;
                               $codeCoverageResult.text($detailResult);
                               //$codeCoverageResult.text(JSON.stringify(buildCoverage))
                               return WidgetHelpers.WidgetStatusHelper.Success();
                           }, function (error) {
                               return WidgetHelpers.WidgetStatusHelper.Failure(error.message);
                           });
                }
                return {
                    load: function (widgetSettings) {
                        var $title = $('h2.title');
                        $title.text('starain widget custom');
                        return getCodeCoverage(widgetSettings);
                    }
                }
                //return {
                //    load: function (widgetSettings) {
                //        var $title = $('h2.title');
                //        $title.text('starain widget custom');
                //        return WidgetHelpers.WidgetStatusHelper.Success();
                //    }
                //}
            });
            VSS.notifyLoadSucceeded();
        });
    </script>
</head>
<body>
    <div class="widget">
        <h2 class="title">widgets starain</h2>
        <div class="codeCoverage">non code coverage</div>
    </div>
</body>
</html>

之后,您可以将该小部件添加到仪表板并检查代码覆盖率。