我正在使用Visual Studio 2022 Community Edition。每当我删除或重命名现有的测试方法(包括复制、粘贴,然后重命名),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()```
.vs
文件夹。 - Greg Burghardt