我正在使用Visual Studio 2022社区版。每当我删除或重命名现有测试方法(包括复制、粘贴然后重命名)时,Visual Studio在进行更改后无法运行测试。
- 我可以右键单击以前运行过的测试并运行它们,但不能运行任何重命名的测试。同样,自上次成功运行以来创建的任何新测试都会运行,直到我重命名了现有的测试方法。
- 只要没有重命名其他测试,我就可以毫无问题地从头开始创建新测试。
- 当我重新启动Visual Studio时,所有测试都被识别出来,并且在重新启动后运行良好。但是在编写测试时必须不断地重新启动Visual Studio是相当令人沮丧的。我复制/粘贴测试方法并对其进行了多次重命名,这导致每次都发生这个问题。
- 我尝试过删除并重新安装Micosoft .NET.Test.Sdk、MSTest.Adapter和MSTest. TestFramework。我删除了存储库,并重新克隆了存储库,实际上删除了隐藏的.vs文件夹。
- 这发生在两台不同的计算机上,多个解决方案,都引用了相同的回购协议。
- 我已经创建了一个新的.NET 6测试项目,并将所有测试从以前的项目复制并粘贴到新项目中。当我尝试运行下面列出的测试后,我确实收到了几个错误。
System.InvalidOperationException: TestsForOrigin: Unknown TestCaseRecord.Origin value Unknown
at Microsoft.VisualStudio.TestStorage.MergedTestGroup.TestsForOrigin(TestCaseOrigin origin)
at Microsoft.VisualStudio.TestStorage.MergedTestGroup.MarkAsStale()
at Microsoft.VisualStudio.TestStorage.MergedTestIndex.MarkAsStale(TestCaseOriginKind originKind)
at Microsoft.VisualStudio.TestStorage.TestStoreIndexSet.MarkTestsAsStale(TestCaseOriginKind originKind)
at Microsoft.VisualStudio.TestStorage.TestStore.MarkTestsAsStale(TestCaseOriginKind originKind)
at Microsoft.VisualStudio.TestWindow.Host.TestRunSession.StartTestRun(IEnumerable`1 containers, IEnumerable`1 requestedTestCasesToRun, Boolean isHotReloadRun)
at Microsoft.VisualStudio.TestWindow.Host.VsTestRunSession.StartTestRun(IEnumerable`1 containers, IEnumerable`1 requestedTestCasesToRun, Boolean isHotReloadedRun, Int32 totalIterations)
at Microsoft.VisualStudio.TestWindow.Host.VsTestRunSession.StartTestRun(ICollection`1 requests, Int32 totalIterations)
at Microsoft.VisualStudio.TestWindow.Logging.ILoggerExtensions.CallInternalWithLogging(IInternalLogger log, Action action, Boolean shouldThrow)
System.Collections.Generic.KeyNotFoundException: The given key 'C:\Users\My Name Removed\source\repos\RepoNameRemoved\LibraryRenamed.ClassRenamed.Tests\bin\Debug\net6.0\LibraryRenamed.ClassRenamed.Tests.dll' was not present in the dictionary.
at System.Collections.Immutable.ImmutableDictionary`2.get_Item(TKey key)
at Microsoft.VisualStudio.TestWindow.Host.VsTestRunSession.ToTestResultRecord(TestResultRecord testResult, IImmutableDictionary`2 containerLookup, TestStore store, Int32 testRunIndex, Boolean isHotReloadedRun, Int32 currentIteration)
at Microsoft.VisualStudio.TestWindow.Host.VsTestRunSession.ToLocalTestResultRecord(TestResultRecord testResult)
at System.Linq.Enumerable.WhereSelectListIterator`2.MoveNext()
at Microsoft.VisualStudio.TestWindow.Host.TestRunSession.AddTestResultRecords(IEnumerable`1 testResultRecords)
at Microsoft.VisualStudio.TestWindow.Host.VsTestRunSession.AddRemoteTestResultRecords(IEnumerable`1 testResults)
at Microsoft.VisualStudio.TestWindow.Host.VsTestRunSession.OnTestRunUpdate(IEnumerable`1 testResults, IEnumerable`1 activeTests)
at Microsoft.VisualStudio.TestWindow.Host.TestPlatformProvider.TestResponseHandler.<>c__DisplayClass16_0.<HandleTestRunStatsChangeAsync>b__0()
at Microsoft.VisualStudio.TestWindow.Logging.ILoggerExtensions.CallInternalWithLogging(IInternalLogger log, Action action, Boolean shouldThrow)
System.Collections.Generic.KeyNotFoundException: The given key 'C:\Users\My Name Removed\source\repos\RepoNameRemoved\LibraryRenamed.ClassRenamed.Tests\bin\Debug\net6.0\LibraryRenamed.ClassRenamed.Tests.dll' was not present in the dictionary.
at System.Collections.Immutable.ImmutableDictionary`2.get_Item(TKey key)
at Microsoft.VisualStudio.TestWindow.Host.VsTestRunSession.ToTestResultRecord(TestResultRecord testResult, IImmutableDictionary`2 containerLookup, TestStore store, Int32 testRunIndex, Boolean isHotReloadedRun, Int32 currentIteration)
at Microsoft.VisualStudio.TestWindow.Host.VsTestRunSession.ToLocalTestResultRecord(TestResultRecord testResult)
at System.Linq.Enumerable.WhereSelectListIterator`2.MoveNext()
at Microsoft.VisualStudio.TestWindow.Host.TestRunSession.AddTestResultRecords(IEnumerable`1 testResultRecords)
at Microsoft.VisualStudio.TestWindow.Host.VsTestRunSession.AddRemoteTestResultRecords(IEnumerable`1 testResults)
at Microsoft.VisualStudio.TestWindow.Host.VsTestRunSession.OnTestRunUpdate(IEnumerable`1 testResults, IEnumerable`1 activeTests)
at Microsoft.VisualStudio.TestWindow.Host.TestPlatformProvider.TestResponseHandler.<>c__DisplayClass16_0.<HandleTestRunStatsChangeAsync>b__0()
at Microsoft.VisualStudio.TestWindow.Logging.ILoggerExtensions.CallInternalWithLogging(IInternalLogger log, Action action, Boolean shouldThrow)
System.Collections.Generic.KeyNotFoundException: The given key 'C:\Users\My Name Removed\source\repos\RepoNameRemoved\LibraryRenamed.ClassRenamed.Tests\bin\Debug\net6.0\LibraryRenamed.ClassRenamed.Tests.dll' was not present in the dictionary.
at System.Collections.Immutable.ImmutableDictionary`2.get_Item(TKey key)
at Microsoft.VisualStudio.TestWindow.Host.VsTestRunSession.ToTestResultRecord(TestResultRecord testResult, IImmutableDictionary`2 containerLookup, TestStore store, Int32 testRunIndex, Boolean isHotReloadedRun, Int32 currentIteration)
at Microsoft.VisualStudio.TestWindow.Host.VsTestRunSession.ToLocalTestResultRecord(TestResultRecord testResult)
at System.Linq.Enumerable.WhereSelectListIterator`2.MoveNext()
at Microsoft.VisualStudio.TestWindow.Host.TestRunSession.AddTestResultRecords(IEnumerable`1 testResultRecords)
at Microsoft.VisualStudio.TestWindow.Host.VsTestRunSession.AddRemoteTestResultRecords(IEnumerable`1 testResults)
at Microsoft.VisualStudio.TestWindow.Host.VsTestRunSession.OnTestRunUpdate(IEnumerable`1 testResults, IEnumerable`1 activeTests)
at Microsoft.VisualStudio.TestWindow.Host.TestPlatformProvider.TestResponseHandler.<>c__DisplayClass16_0.<HandleTestRunStatsChangeAsync>b__0()
at Microsoft.VisualStudio.TestWindow.Logging.ILoggerExtensions.CallInternalWithLogging(IInternalLogger log, Action action, Boolean shouldThrow)
System.Collections.Generic.KeyNotFoundException: The given key 'C:\Users\My Name Removed\source\repos\RepoNameRemoved\LibraryRenamed.ClassRenamed.Tests\bin\Debug\net6.0\LibraryRenamed.ClassRenamed.Tests.dll' was not present in the dictionary.
at System.Collections.Immutable.ImmutableDictionary`2.get_Item(TKey key)
at Microsoft.VisualStudio.TestWindow.Host.VsTestRunSession.ToTestResultRecord(TestResultRecord testResult, IImmutableDictionary`2 containerLookup, TestStore store, Int32 testRunIndex, Boolean isHotReloadedRun, Int32 currentIteration)
at Microsoft.VisualStudio.TestWindow.Host.VsTestRunSession.ToLocalTestResultRecord(TestResultRecord testResult)
at System.Linq.Enumerable.WhereSelectListIterator`2.MoveNext()
at Microsoft.VisualStudio.TestWindow.Host.TestRunSession.AddTestResultRecords(IEnumerable`1 testResultRecords)
at Microsoft.VisualStudio.TestWindow.Host.VsTestRunSession.AddRemoteTestResultRecords(IEnumerable`1 testResults)
at Microsoft.VisualStudio.TestWindow.Host.VsTestRunSession.OnTestRunUpdate(IEnumerable`1 testResults, IEnumerable`1 activeTests)
at Microsoft.VisualStudio.TestWindow.Host.TestPlatformProvider.TestResponseHandler.<>c__DisplayClass16_0.<HandleTestRunStatsChangeAsync>b__0()
at Microsoft.VisualStudio.TestWindow.Logging.ILoggerExtensions.CallInternalWithLogging(IInternalLogger log, Action action, Boolean shouldThrow)
System.Collections.Generic.KeyNotFoundException: The given key 'C:\Users\My Name Removed\source\repos\RepoNameRemoved\LibraryRenamed.ClassRenamed.Tests\bin\Debug\net6.0\LibraryRenamed.ClassRenamed.Tests.dll' was not present in the dictionary.
at System.Collections.Immutable.ImmutableDictionary`2.get_Item(TKey key)
at Microsoft.VisualStudio.TestWindow.Host.VsTestRunSession.ToTestResultRecord(TestResultRecord testResult, IImmutableDictionary`2 containerLookup, TestStore store, Int32 testRunIndex, Boolean isHotReloadedRun, Int32 currentIteration)
at Microsoft.VisualStudio.TestWindow.Host.VsTestRunSession.ToLocalTestResultRecord(TestResultRecord testResult)
at System.Linq.Enumerable.WhereSelectListIterator`2.MoveNext()
at Microsoft.VisualStudio.TestWindow.Host.TestRunSession.AddTestResultRecords(IEnumerable`1 testResultRecords)
at Microsoft.VisualStudio.TestWindow.Host.VsTestRunSession.AddRemoteTestResultRecords(IEnumerable`1 testResults)
at Microsoft.VisualStudio.TestWindow.Host.VsTestRunSession.OnTestRunUpdate(IEnumerable`1 testResults, IEnumerable`1 activeTests)
at Microsoft.VisualStudio.TestWindow.Host.TestPlatformProvider.TestResponseHandler.<>c__DisplayClass16_0.<HandleTestRunStatsChangeAsync>b__0()
at Microsoft.VisualStudio.TestWindow.Logging.ILoggerExtensions.CallInternalWithLogging(IInternalLogger log, Action action, Boolean shouldThrow)
System.Collections.Generic.KeyNotFoundException: The given key 'C:\Users\My Name Removed\source\repos\RepoNameRemoved\LibraryRenamed.ClassRenamed.Tests\bin\Debug\net6.0\LibraryRenamed.ClassRenamed.Tests.dll' was not present in the dictionary.
at System.Collections.Immutable.ImmutableDictionary`2.get_Item(TKey key)
at Microsoft.VisualStudio.TestWindow.Host.VsTestRunSession.ToTestResultRecord(TestResultRecord testResult, IImmutableDictionary`2 containerLookup, TestStore store, Int32 testRunIndex, Boolean isHotReloadedRun, Int32 currentIteration)
at Microsoft.VisualStudio.TestWindow.Host.VsTestRunSession.ToLocalTestResultRecord(TestResultRecord testResult)
at System.Linq.Enumerable.WhereSelectListIterator`2.MoveNext()
at Microsoft.VisualStudio.TestWindow.Host.TestRunSession.AddTestResultRecords(IEnumerable`1 testResultRecords)
at Microsoft.VisualStudio.TestWindow.Host.VsTestRunSession.AddRemoteTestResultRecords(IEnumerable`1 testResults)
at Microsoft.VisualStudio.TestWindow.Host.VsTestRunSession.OnTestRunUpdate(IEnumerable`1 testResults, IEnumerable`1 activeTests)
at Microsoft.VisualStudio.TestWindow.Host.TestPlatformProvider.TestResponseHandler.<>c__DisplayClass16_0.<HandleTestRunStatsChangeAsync>b__0()
at Microsoft.VisualStudio.TestWindow.Logging.ILoggerExtensions.CallInternalWithLogging(IInternalLogger log, Action action, Boolean shouldThrow)
System.Collections.Generic.KeyNotFoundException: The given key 'C:\Users\My Name Removed\source\repos\RepoNameRemoved\LibraryRenamed.ClassRenamed.Tests\bin\Debug\net6.0\LibraryRenamed.ClassRenamed.Tests.dll' was not present in the dictionary.
at System.Collections.Immutable.ImmutableDictionary`2.get_Item(TKey key)
at Microsoft.VisualStudio.TestWindow.Host.VsTestRunSession.ToTestResultRecord(TestResultRecord testResult, IImmutableDictionary`2 containerLookup, TestStore store, Int32 testRunIndex, Boolean isHotReloadedRun, Int32 currentIteration)
at Microsoft.VisualStudio.TestWindow.Host.VsTestRunSession.ToLocalTestResultRecord(TestResultRecord testResult)
at System.Linq.Enumerable.WhereSelectListIterator`2.MoveNext()
at Microsoft.VisualStudio.TestWindow.Host.TestRunSession.AddTestResultRecords(IEnumerable`1 testResultRecords)
at Microsoft.VisualStudio.TestWindow.Host.VsTestRunSession.AddRemoteTestResultRecords(IEnumerable`1 testResults)
at Microsoft.VisualStudio.TestWindow.Host.VsTestRunSession.OnTestRunUpdate(IEnumerable`1 testResults, IEnumerable`1 activeTests)
at Microsoft.VisualStudio.TestWindow.Host.TestPlatformProvider.TestResponseHandler.<>c__DisplayClass16_0.<HandleTestRunStatsChangeAsync>b__0()
at Microsoft.VisualStudio.TestWindow.Logging.ILoggerExtensions.CallInternalWithLogging(IInternalLogger log, Action action, Boolean shouldThrow)
System.Collections.Generic.KeyNotFoundException: The given key 'C:\Users\My Name Removed\source\repos\RepoNameRemoved\LibraryRenamed.ClassRenamed.Tests\bin\Debug\net6.0\LibraryRenamed.ClassRenamed.Tests.dll' was not present in the dictionary.
at System.Collections.Immutable.ImmutableDictionary`2.get_Item(TKey key)
at Microsoft.VisualStudio.TestWindow.Host.VsTestRunSession.ToTestResultRecord(TestResultRecord testResult, IImmutableDictionary`2 containerLookup, TestStore store, Int32 testRunIndex, Boolean isHotReloadedRun, Int32 currentIteration)
at Microsoft.VisualStudio.TestWindow.Host.VsTestRunSession.ToLocalTestResultRecord(TestResultRecord testResult)
at System.Linq.Enumerable.WhereSelectListIterator`2.MoveNext()
at Microsoft.VisualStudio.TestWindow.Host.TestRunSession.AddTestResultRecords(IEnumerable`1 testResultRecords)
at Microsoft.VisualStudio.TestWindow.Host.VsTestRunSession.AddRemoteTestResultRecords(IEnumerable`1 testResults)
at Microsoft.VisualStudio.TestWindow.Host.VsTestRunSession.OnTestRunUpdate(IEnumerable`1 testResults, IEnumerable`1 activeTests)
at Microsoft.VisualStudio.TestWindow.Host.TestPlatformProvider.TestResponseHandler.<>c__DisplayClass16_0.<HandleTestRunStatsChangeAsync>b__0()
at Microsoft.VisualStudio.TestWindow.Logging.ILoggerExtensions.CallInternalWithLogging(IInternalLogger log, Action action, Boolean shouldThrow)
System.Collections.Generic.KeyNotFoundException: The given key 'C:\Users\My Name Removed\source\repos\RepoNameRemoved\LibraryRenamed.ClassRenamed.Tests\bin\Debug\net6.0\LibraryRenamed.ClassRenamed.Tests.dll' was not present in the dictionary.
at System.Collections.Immutable.ImmutableDictionary`2.get_Item(TKey key)
at Microsoft.VisualStudio.TestWindow.Host.VsTestRunSession.ToTestResultRecord(TestResultRecord testResult, IImmutableDictionary`2 containerLookup, TestStore store, Int32 testRunIndex, Boolean isHotReloadedRun, Int32 currentIteration)
at Microsoft.VisualStudio.TestWindow.Host.VsTestRunSession.ToLocalTestResultRecord(TestResultRecord testResult)
at System.Linq.Enumerable.WhereSelectListIterator`2.MoveNext()
at Microsoft.VisualStudio.TestWindow.Host.TestRunSession.AddTestResultRecords(IEnumerable`1 testResultRecords)
at Microsoft.VisualStudio.TestWindow.Host.VsTestRunSession.AddRemoteTestResultRecords(IEnumerable`1 testResults)
at Microsoft.VisualStudio.TestWindow.Host.VsTestRunSession.OnTestRunUpdate(IEnumerable`1 testResults, IEnumerable`1 activeTests)
at Microsoft.VisualStudio.TestWindow.Host.TestPlatformProvider.TestResponseHandler.<>c__DisplayClass16_0.<HandleTestRunStatsChangeAsync>b__0()
at Microsoft.VisualStudio.TestWindow.Logging.ILoggerExtensions.CallInternalWithLogging(IInternalLogger log, Action action, Boolean shouldThrow)
System.InvalidOperationException: TestsForOrigin: Unknown TestCaseRecord.Origin value Unknown
at Microsoft.VisualStudio.TestStorage.MergedTestGroup.TestsForOrigin(TestCaseOrigin origin)
at Microsoft.VisualStudio.TestStorage.MergedTestGroup.MarkAsNotRunningAndNotPending()
at Microsoft.VisualStudio.TestStorage.MergedTestIndex.MarkAsNotRunningAndNotPending(TestCaseOriginKind originKind)
at Microsoft.VisualStudio.TestStorage.TestStoreIndexSet.MarkTestsAsNotRunningAndNotPending(TestCaseOriginKind originKind)
at Microsoft.VisualStudio.TestStorage.TestStore.MarkTestsAsNotRunningAndNotPending(TestCaseOriginKind originKind)
at Microsoft.VisualStudio.TestWindow.Host.VsTestRunSession.EndTestRun()
at Microsoft.VisualStudio.TestWindow.Host.VsTestRunSession.OnTestRunCompleted()
at Microsoft.VisualStudio.TestWindow.Utilities.EventPumpExtensions.<>c__DisplayClass0_0.<EnqueueAsync>b__0()
--- End of stack trace from previous location where exception was thrown ---
at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
at Microsoft.VisualStudio.TestWindow.Host.TestPlatformProvider.<RunTestsAsync>d__27.MoveNext()
--- End of stack trace from previous location where exception was thrown ---
at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
at Microsoft.VisualStudio.TestWindow.Host.TestPlatformProvider.<RunTestsAsync>d__25.MoveNext()
--- End of stack trace from previous location where exception was thrown ---
at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
at Microsoft.VisualStudio.TestWindow.Logging.ILoggerExtensions.<CallWithCatchAsync>d__11`1.MoveNext()```
1条答案
按热度按时间11dmarpk1#
我遇到了同样的问题。有趣的是,一个简单的Visual Studio重启就解决了这个问题。看起来我们还可以将MSTest.TestAdapter和MSTest.TestFramework NuGet包降级到2.2.8。
重启的想法来自这里:https://github.com/microsoft/vstest/issues/4208
这似乎是一个最近的bug,上周开始弹出。看起来修复已经在进行中:
奥斯瓦尔多·卡列斯[微软]:我们已经有了一个修复程序,但它还在代码评审中。不幸的是,除了将NuGet包版本降级到2.2.8之外,没有其他解决方案。https://developercommunity.visualstudio.com/t/Unit-test-startup-fails-with-an-exceptio/10226576