首页 > 解决方案 > 当执行单元测试步骤时以前工作的 VSTS 构建超时时,如何将更好的日志记录添加到调试中

问题描述

我有一个带有单元测试的 VSTS 构建,以前在 VSTS 构建中工作过。本周,由于超时而停止工作。

由于 60 分钟后超时而发生故障。以下是我们所知道的:

有没有人对其他事情有其他建议来尝试缩小可能导致这种情况的范围(例如,VSTS 中的跟踪日志记录)?下面的日志文件显示了我们单元测试配置的一些细节,但如果其他细节有帮助,请告诉我。

失败日志如下所示:

> ============================================================================== 2018-07-18T20:14:25.1963123Z Run the tests locally using
> vstest.console.exe 2018-07-18T20:14:25.1964566Z
> ======================================================== 2018-07-18T20:14:25.1965645Z Test selector : Test assemblies
> 2018-07-18T20:14:25.1966925Z Test assemblies : **\<PathToTestLib>.dll
> 2018-07-18T20:14:25.1968187Z Test filter criteria : null
> 2018-07-18T20:14:25.1968810Z Search folder : C:\vsts-agent\_work\4\s
> 2018-07-18T20:14:25.1969311Z Run settings file :
> C:\vsts-agent\_work\4\s 2018-07-18T20:14:25.1970327Z Run in parallel :
> false 2018-07-18T20:14:25.1970792Z Run in isolation : false
> 2018-07-18T20:14:25.1972913Z Path to custom adapters : null
> 2018-07-18T20:14:25.1973153Z Other console options : null
> 2018-07-18T20:14:25.1973381Z Code coverage enabled : false
> 2018-07-18T20:14:25.1974004Z Rerun failed tests: false
> 2018-07-18T20:14:25.1974423Z VisualStudio version selected for test
> execution : latest 2018-07-18T20:14:25.3811086Z
> ======================================================== 2018-07-18T20:14:30.6014691Z [command]"C:\Program Files
> (x86)\Microsoft Visual
> Studio\2017\Enterprise\Common7\IDE\CommonExtensions\Microsoft\TestWindow\vstest.console.exe"
> @C:\vsts-agent\_work\_temp\2aa40f41-8ac7-11e8-b190-a1cdff2b8b30.txt
> 2018-07-18T20:14:30.8198002Z Microsoft (R) Test Execution Command Line
> Tool Version 15.7.2 2018-07-18T20:14:30.8206458Z Copyright (c)
> Microsoft Corporation.  All rights reserved.
> 2018-07-18T20:14:30.8206862Z  2018-07-18T20:14:30.8227447Z
> vstest.console.exe  2018-07-18T20:14:30.8228082Z
> "C:\vsts-agent\_work\4\s\partners\exooutlook\OutlookAnalysisSolution.Test\bin\Debug\OutlookAnalysisSolution.Test.dll"
> 2018-07-18T20:14:30.8228647Z /logger:"trx"
> 2018-07-18T20:14:31.0672644Z Starting test execution, please wait...
> 2018-07-18T21:14:05.8979923Z ##[error]The operation was canceled.
> 2018-07-18T21:14:05.9027909Z ##[section]Finishing: Unit Tests

标签: unit-testingazure-devopsazure-pipelines

解决方案


我们找到了挂起的根源。它位于标有“AssemblyInitialize”属性的测试类方法中。

    [TestClass]
public class TestClassInitializer
{
    [AssemblyInitialize]
    public static void AssemblyInit(TestContext context)
    {
        LocalResourceDeployment.CopyResources();
    }
}

CopyResources() 中存在一个错误,该错误未在本地显示,但导致 VSTS 中的 powershell 窗口等待控制台输入。

我们已经改进了这个初始化方法中的跟踪日志记录,这样如果将来它再次失败,我们至少会有一个指向测试卡住的地方的指针。例如:

Trace.WriteLine("Starting test assembly initializtion.");

推荐阅读