【发布时间】:2020-12-03 17:47:25
【问题描述】:
单元测试调用以下方法。它在本地运行时通过,但在作为 Azure DevOps 构建管道的一部分运行时由于 assembly.GetTypes() 上的 LoaderException 而失败。我不确定如何调试它,因为它不会在本地发生。通常我会在调试模式下运行它并查看 LoaderException。管道任务 VSTest@2 只记录堆栈跟踪
Assembly[] assemblies = AppDomain.CurrentDomain.GetAssemblies();
foreach (Assembly assembly in assemblies)
{
if (assembly != null)
{ Type[] types = assembly.GetTypes(); }
}
Test method
Tests.Data.IBlockConversionTests.TestIBlockConversion threw exception:
System.Reflection.ReflectionTypeLoadException: Unable to load one or more of the requested types. Retrieve the LoaderExceptions property for more information.
Stack Trace:
at System.Reflection.RuntimeModule.GetTypes(RuntimeModule module)
at System.Reflection.RuntimeModule.GetTypes()
at System.Reflection.Assembly.GetTypes()
at Plugin.PluginLoader`1.LoadPlugins(IEnumerable`1 assemblies) in D:\a\1\s\Core\Plugin\Plugin\PluginLoader.cs:line 80
at Tests.Data.IBlockConversionTests.TestIBlockConversion() in D:\a\1\s\Tests\Data\IBlockConversionTests.cs:line 42
【问题讨论】:
-
首先查看
LoaderException的异常消息,以及任何InnerExceptions -
在管道上运行单元测试时我该怎么做?
-
此构建管道系统中是否存在日志记录工具?
-
看看你的测试输出?捕获异常并记录您需要的所有内容?创建一个专门的控制台应用程序来重现问题并打印您需要的内容?富有想象力!
-
将 Syste.Debug 设置为 true docs.microsoft.com/en-us/azure/devops/pipelines/build/… 以检查是否会有有趣的事情
标签: c# unit-testing azure-devops pipeline assemblies