gpt4 book ai didi

c# - Visual Studio 2017 + .Net Core 2 测试不可执行

转载 作者:太空狗 更新时间:2023-10-29 22:29:44 24 4
gpt4 key购买 nike

我正在尝试为私有(private)项目设置一些单元测试。由于我不介意确切的运行者,我尝试了 NUnit、XUnit 和 MStest,但到目前为止都没有成功。

经过一些研究,我在这里克隆了官方的 Microsoft 存储库:https://github.com/dotnet/docs/blob/master/samples/core/getting-started/unit-testing-using-nunit/PrimeService.Tests/PrimeService_IsPrimeShould.cs但是这些测试也不能执行。这样做时,我在输出中收到以下错误:

System.ArgumentException: Illegal characters in path. at System.IO.Path.CheckInvalidPathChars(String path, Boolean checkAdditional) at System.IO.Path.Combine(String path1, String path2) at Microsoft.VisualStudio.TestPlatform.CrossPlatEngine.Helpers.DotnetHostHelper.TryGetExecutablePath(String executableBaseName, String& executablePath) at Microsoft.VisualStudio.TestPlatform.CrossPlatEngine.Helpers.DotnetHostHelper.GetDotnetPath() at Microsoft.VisualStudio.TestPlatform.CrossPlatEngine.Hosting.DotnetTestHostManager.GetTestHostProcessStartInfo(IEnumerable1
sources, IDictionary
2 environmentVariables, TestRunnerConnectionInfo connectionInfo) at Microsoft.VisualStudio.TestPlatform.CrossPlatEngine.Client.ProxyOperationManager.SetupChannel(IEnumerable`1 sources, CancellationToken cancellationToken) at Microsoft.VisualStudio.TestPlatform.CrossPlatEngine.Client.ProxyDiscoveryManager.DiscoverTests(DiscoveryCriteria discoveryCriteria, ITestDiscoveryEventsHandler2 eventHandler)

我还检查了几个 SO 答案,例如 Unit Tests not discovered in Visual Studio 2017How to run NUnit tests in Visual Studio 2017? , 但都没有解决问题。

我的 Visual Studio 2017 版本目前是 15.6.0,我也在使用 ReSharper。这似乎是一个本地环境问题,不幸的是,我没有找到有关该问题的任何提示。有没有人知道如何解决这个问题?

最佳答案

在大型解决方案上从 NUnit 迁移到 XUnit 后,我​​遇到了完全相同的问题。

我尝试创建一个仅包含一个虚拟测试的新项目。这也展示了问题,这意味着它是环境问题。

我最终发现 Git 在 PATH 环境变量中的条目周围放置了双引号,如下所示:

...;"C:\Program Files (x86)\Git\bin";...

不幸的是,我的路径很长(3600 个字符),所以 Windows GUI 不允许我更改它,因为它超过了 2047 个字符。

我能够通过更改存储在 Windows 注册表中的路径 Computer\HKEY_LOCAL_MACHINE\SYSTEM\ControlSet001\Control\Session Manager\Environment 来更正它

我能够通过将引号重新添加到 Path 环境变量来随意重现该行为。

我认为我(很久以前)安装的旧版本 Git 存在一个错误,它将引用的 locate 添加到路径环境变量中,而较新的更新从未改变它。我怀疑 NUnit 测试运行器可以容忍引号,而 XUnit 测试运行器则不能。

希望我的经验对您的问题有所帮助。

关于c# - Visual Studio 2017 + .Net Core 2 测试不可执行,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/49337947/

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