gpt4 book ai didi

c# - 编码的 UI 测试现在收到有关未找到 Newtonsoft.json 的错误

转载 作者:太空宇宙 更新时间:2023-11-03 15:43:38 25 4
gpt4 key购买 nike

我有一个简单的编码 UI 测试来登录应用程序。该测试是数据驱动的,并使用来自 TFS 的数据。我们正在使用服务器和代理系统上的 TfsTestAgent 用户(具有管理员权限)。当我执行测试时,我看到以下错误:

    The unit test adapter failed to connect to the data source or to read the data.
For more information on troubleshooting this error, see "Troubleshooting Data-Driven
Unit Tests" (http://go.microsoft.com/fwlink/?LinkId=62412) in the MSDN Library.Error
details: Could not load file or assembly 'Newtonsoft.Json, Version=4.5.0.0,
Culture=neutral, PublicKeyToken=30ad4fe6b2a6aeed' or one of its dependencies. The
system cannot find the file specified.

测试运行日志 (UITestLog.html) 显示如下:

I, 2524, 81, 2015/03/24, 13:27:09.815, 14494724802, QTAgent32_40.exe, ExtensionFramework : Reading extensions from custom dir 'C:\Program Files (x86)\Common Files\Microsoft Shared\VSTT\12.0\UITestExtensionPackages'
V, 2524, 81, 2015/03/24, 13:27:09.830, .\QTAgent32_40.exe, UnitTestExecuter.RunClassInitializeMethod: Acquiring m_runner.SyncRoot.
V, 2524, 81, 2015/03/24, 13:27:09.830, .\QTAgent32_40.exe, UnitTestExecuter.RunClassInitializeMethod: Acquired m_runner.SyncRoot.
V, 2524, 81, 2015/03/24, 13:27:09.830, .\QTAgent32_40.exe, CodedUITest : CodedUITestExtension.BeforeClassInitialize()
V, 2524, 81, 2015/03/24, 13:27:09.830, .\QTAgent32_40.exe, CodedUITest : CodedUITestExtension.AfterClassInitialize()
V, 2524, 81, 2015/03/24, 13:27:09.830, .\QTAgent32_40.exe, UnitTestExecuter.RunClassInitializeMethod: Released m_runner.SyncRoot.
V, 2524, 81, 2015/03/24, 13:27:09.830, .\QTAgent32_40.exe, UnitTestRunner.ExecuteDataDrivenTest: started.
V, 2524, 8, 2015/03/24, 13:27:10.377, .\QTAgent32_40.exe, CodedUITest : CodedUITestExtension.BeforeClassCleanup
V, 2524, 8, 2015/03/24, 13:27:10.377, .\QTAgent32_40.exe, CodedUITest : CodedUITestExtension.AfterClassCleanup
V, 2524, 8, 2015/03/24, 13:27:10.393, .\QTAgent32_40.exe, CodedUITest : CodedUITestExtension.Dispose()
I, 2524, 8, 2015/03/24, 13:27:10.393, .\QTAgent32_40.exe, UnitTestRunner.Dispose.

有趣的是,项目中根本没有使用 Newtonsoft.Json(又名 Json.Net),也没有使用任何引用的库。从上面的日志中,在我看来,这在编码的 UI 测试之外,因为它没有注册为脚本异常。

那么问题是,为什么在更改 Coded UI 系统运行测试的用户后开始?我已经尝试通过快照将其还原为原始用户(并在测试管理器中更改主机环境)。这样做给了我上面相同的结果。

我正在寻找进一步调试此问题的任何方法或修复的想法。我尝试了以下失败修复:

  • 在解决方案中包含 Newtonsoft.Json
  • 将库复制到 c:\Program Files (x86)\Microsoft Visual Studio 12.0\Common7\IDE\PublicAssemblies
  • 恢复到一个已知的工作构建并运行它(仍然得到同样的错误)

值得注意的是最后一项。我有一些我知道可以在多台机器上工作的构建。在任何机器上使用这些构建都会产生相同的结果。是什么导致该错误消息并独立于机器/测试代码?

最佳答案

错误

错误信息是

Could not load file or assembly 'Newtonsoft.Json, Version=4.5.0.0, Culture=neutral, PublicKeyToken=30ad4fe6b2a6aeed' or one of its dependencies.

这里要知道的一件事是这个错误有两个选项:

  1. 找不到 Newtonsoft.Json
  2. 找不到依赖项

分析

分析此类问题的典型方法是使用 Process Monitor [Microsoft SysInternals] .

如果您想完全手动完成,请按照以下步骤操作:

  1. 运行进程监视器
  2. 为有问题的可执行文件添加过滤器
  3. 重现问题
  4. 问题重现后停止记录事件
  5. 艰巨的任务:从底部开始查找错误找不到名称找不到路径拒绝访问。您必须找到一个有问题的 DLL,并且之后没有 Success(如果在搜索路径中发现 DLL 较晚,则可能会发生这种情况)。

我已将此过程自动化并提供 Process Monitor Log Analyzer下载。免责声明:我是这个免费工具的作者。

使用该工具的步骤是:

  1. 运行进程监视器
  2. 为有问题的可执行文件添加过滤器
  3. 重现问题
  4. 问题重现后停止记录事件
  5. 将 Process Monitor 日志保存为 XML
  6. 在 Process Monitor Log Analyzer 中打开 XML
  7. 从上到下浏览项目

您的问题

The question then is, why did this start after changing the user that the Coded UI system runs tests under?

也许“旧”用户有足够的访问权限而"new"用户没有。这不应该是管理员用户的原因(尽管仍然可能)。

也许“旧”用户在 PATH 中有不同的文件夹,而"new"用户没有。

The interesting thing is that Newtonsoft.Json (aka Json.Net) isn't used in the project at all or any referenced libraries.

我想知道你是如何检查的。请注意,您不能简单地使用 Dependency Walker对于.NET。您需要特定于 .NET 的东西,例如dotPeek [JetBrains] ,但 dotPeek 不会一次显示所有依赖项,您需要手动查看所有引用。但是,这不会找到丢失的 native DLL。因此,对我来说最可靠的方法是前面所述的 Process Monitor。

What could cause that error message and be machine/test code independent?

和以前一样:用户特定的配置。

关于c# - 编码的 UI 测试现在收到有关未找到 Newtonsoft.json 的错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/29241979/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com