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

标签 c# visual-studio visual-studio-2017

我正在尝试为私有(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, IDictionary2 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/

相关文章:

c# - 如何在 C# 中实现常量正确性?

c# - 如何在 C# 中使用派生类型覆盖泛型方法

c++ - 调试 MFC : "mfc100.dll" cannot find or open pdb

git - 如何在 visual studio git 中显示文件夹的历史记录

visual-studio-2017 - VS2017中的警告,但VS2015都很好

uwp - 通过App Installer安装UWP应用程序出现网络错误,依赖包丢失

C# Silverlight 3 - 以编程方式在页面之间导航?

c# - Entity Framework 6 上的数据库迁移问题

ios - "A valid provisioning profile for this executable was not found"用于 Xamarin.Forms iOS RELEASE 构建到 iPhone 设备

c# - 正则表达式特周