所有测试通过后,TFS上的VS测试步骤失败

时间:2016-09-04 17:05:48

标签: unit-testing tfs visual-studio-2015 nunit nunit-3.0

我有一组使用VS Test步骤在TFS 2015中运行的MsTest和NUnit测试。我使用NUnit Test Adapter 3.4.1在构建代理上运行测试。

最后,即使测试通过,Nunit似乎也会嘎然而且构建步骤因这两个错误而失败。

2016-09-04T09:59:44.7209787Z ##[error]Error: Exception NUnit.Engine.NUnitEngineException, Exception thrown executing tests
2016-09-04T09:59:44.7209787Z ##[error]
2016-09-04T09:59:44.7209787Z ##[error]Error: Exception encountered unloading AppDomain
2016-09-04T09:59:44.7209787Z ##[error]
2016-09-04T09:59:44.7209787Z Information: NUnit Adapter 3.4.1.0: Test execution complete
2016-09-04T09:59:44.8615975Z Results File: C:\agent\_work2\1\TestResults\SRV-BLD1 2016-09-04 01_22_45.trx
2016-09-04T09:59:44.8615975Z Total tests: 139. Passed: 134. Failed: 0. Skipped: 5.

我已经检查过套件中确实有139个测试,并且有5个被设置为忽略(2个是MSTest,3个是NUnit)。

我不确定是否有地方可以获得有关错误的更详细说明。搜索此网站和谷歌似乎暗示NUnit.Engine.NUnitEngineException链接到测试发现(例如herehere),但我的测试正在被发现,所以我是不确定这是否相关(对NUnit来说很新,所以不确定很多事情。)

我还看到两个处理适配器故障的链接(herehere),但错误并不完全匹配,但可能只是因为我没有相同程度的冗长。

在TFS中,该步骤没有任何配置,只是它已启用并且是DLL的路径。

有谁知道导致错误的原因(我假设导致构建失败)?或者,在获得更精确/详细的错误堆栈以调查问题的后续步骤应该是什么?

作为旁注,我看到了this SO回答,其中说明了这一点:

  

MSTest.exe返回退出代码1表示并非所有测试   过去了。

在遇到Skipped测试时,我无法找到VSTests失败的确认信息,但这也可能是一个问题吗?

感谢您的帮助。

更新

如下所示,我尝试直接从IDE运行此命令,并获得此输出(文件夹编辑)

------ Discover test started ------
NUnit Adapter 3.4.1.0: Test discovery starting

NUnit Adapter 3.4.1.0: Test discovery complete
========== Discover test finished: 139 found (0:00:00.8820879) ==========
------ Run test started ------
System.AppDomainUnloadedException: Attempted to access an unloaded AppDomain. This can happen if the test(s) started a thread but did not stop it. Make sure that all the threads started by the test(s) are stopped before completion.
NUnit Adapter 3.4.1.0: Test execution started
Running all tests in C:\agent\_work2\1\s\codePorject\bin\Debug\codeProjectTests.dll
NUnit3TestExecutor converted 37 of 37 NUnit test cases
System.AppDomainUnloadedException: Attempted to access an unloaded AppDomain. This can happen if the test(s) started a thread but did not stop it. Make sure that all the threads started by the test(s) are stopped before completion.
Exception NUnit.Engine.NUnitEngineException, Exception thrown executing tests
Exception encountered unloading AppDomain
NUnit Adapter 3.4.1.0: Test execution complete
========== Run test finished: 139 run (1:20:10.3290294) ==========

我发现了类似的xUnit issue,但它似乎没有解决方案。

This StackOverflow回答建议使用睡眠定时器,所以我可能会试试。

2 个答案:

答案 0 :(得分:1)

最后,它看起来像Firefox浏览器窗口和nUnit之间的某种竞争条件。在我的清理代码中,我正在杀死firefox和iisexpress进程。添加睡眠呼叫消除了这个问题:

public static void AssemblyCleanup()
{
    foreach (var process in Process.GetProcessesByName("firefox")) process.Kill();
    foreach (var process in Process.GetProcessesByName("iisexpress")) process.Kill();
    System.Threading.Thread.Sleep(5000);
}

答案 1 :(得分:0)

NUnitEngineException就是它所说的:引擎发现的异常。它可能是由许多事情引起的,并且消息表明问题。在您的情况下,消息显示“Exception遇到卸载AppDomain”,这意味着......以及它所说的内容。

测试适配器捕获并处理异常,生成您看到的消息。有迹象表明TFS也会看到异常并导致测试运行失败。如果你在VS IDE下运行它,我想你会看到来自适配器的消息,但运行不会失败。有关此问题的NUnit3测试适配器问题,但目前尚不清楚解决方案是否位于适配器内,或者是否是TFS问题。

如果你在IDE下尝试这个,我希望你也会发布该运行的输出窗口文本。

相关问题