Resharper无法运行xUnit测试

9

我有一个使用xUnit的.NET Core项目。然而,无法再使用Resharper运行任何测试了。即使是非常简单的测试也是不确定的。例如:

using Xunit;

public class MyTests
{
    [Fact]
    public void MySuperTest()
    {
        Assert.Equal(1, 1);
    }
}

输出日志显示有一个异常:
2017.08.04 16:58:41.304    INFO BuildStage started
2017.08.04 16:58:41.304    INFO Build policy: Automatic
2017.08.04 16:58:42.636    INFO 1 projects built
2017.08.04 16:58:42.636 VERBOSE     Computershare.AssetManagement.Testing
2017.08.04 16:58:42.637    INFO BuildStage completed
2017.08.04 16:58:42.638    INFO RefreshProjectPropertiesStage started
2017.08.04 16:58:42.638    INFO RefreshProjectPropertiesStage completed
2017.08.04 16:58:42.640    INFO DiscoveryStage started
2017.08.04 16:58:42.641    INFO Test exploration required for 1 projects
2017.08.04 16:58:42.641 VERBOSE     Computershare.AssetManagement.Testing
2017.08.04 16:58:42.643    INFO DiscoveryStage completed
2017.08.04 16:58:42.643    INFO BuildPipelineStage started
2017.08.04 16:58:42.643    INFO BuildPipelineStage completed
2017.08.04 16:58:42.643    INFO ApplyRulesStage started
2017.08.04 16:58:42.647    INFO Got 1 elements (1 explicit) to run
2017.08.04 16:58:42.647    INFO Marking 1 elements as Pending
2017.08.04 16:58:42.679    INFO Marking elements as Pending completed
2017.08.04 16:58:42.679    INFO Distributing 1 elements into runs
2017.08.04 16:58:42.695    INFO Host Controller initialization started
2017.08.04 16:58:42.695 VERBOSE Host Controller: DebugTaskRunnerHostController
2017.08.04 16:58:42.695    INFO Host Controller initialization completed
2017.08.04 16:58:42.721    INFO Distributing elements completed
2017.08.04 16:58:42.721    INFO Created 1 unit-test runs
2017.08.04 16:58:42.721    INFO ApplyRulesStage completed
2017.08.04 16:58:42.721    INFO RunTestsStage started
2017.08.04 16:58:42.722 VERBOSE Running up to 1 unit-test runs in parallel
2017.08.04 16:58:42.727    INFO Run: 28147df6-3156-4f24-bd5a-ca737ab6c43a - Started
2017.08.04 16:58:42.728 VERBOSE     Provider: xUnit.net
    Project: Computershare.AssetManagement.Testing
    Target Framework: .NETCoreApp,Version=v1.1
    Strategy: JetBrains.ReSharper.UnitTestFramework.DotNetCore.DotNetVsTest.DotNetVsTestRunStrategy
    Runtime Enviroment:
        Platform Type: x64
        Platform Version: v4_0
2017.08.04 16:58:42.747   TRACE Register handler for message type 'TestSession.Message', protocol version '1'
2017.08.04 16:58:42.747   TRACE Register handler for message type 'ProtocolVersion', protocol version '<unset>'
2017.08.04 16:58:42.747   TRACE Register handler for message type 'TestSession.Connected', protocol version '<unset>'
2017.08.04 16:58:42.747   TRACE Register handler for message type 'TestExecution.CustomTestHostLaunch', protocol version '1'
2017.08.04 16:58:42.748   TRACE Register handler for message type 'TestExecution.Completed', protocol version '1'
2017.08.04 16:58:42.748   TRACE Register handler for message type 'TestExecution.StatsChange', protocol version '1'
2017.08.04 16:58:42.750    INFO Starting process: dotnet vstest /port:47441 
2017.08.04 16:58:42.754    INFO Started process with pid 12856
2017.08.04 16:58:43.266   TRACE Processing message 'TestSession.Connected'
2017.08.04 16:58:43.266   TRACE Processed message 'TestSession.Connected'
2017.08.04 16:58:43.272   TRACE Processing message 'ProtocolVersion'
2017.08.04 16:58:43.274    INFO Using test adapter: ...PROJECT PATH REMOVED...\bin\Debug\netcoreapp1.1\xunit.runner.visualstudio.dotnetcore.testadapter.dll
2017.08.04 16:58:43.274    WARN File ...PROJECT PATH REMOVED...\bin\Debug\netcoreapp1.1\xunit.runner.visualstudio.dotnetcore.testadapter.dll does not exist on disk
2017.08.04 16:58:43.304   ERROR Transition failed: Transition from state <HandShake> on event <remote::.ProtocolVersion>. Cause: System.InvalidOperationException: Test-cases are missing for the selected tests. Did discovery succeed? at JetBrains.ReSharper.UnitTestFramework.DotNetCore.DotNetVsTest.DotNetVsTestExecution.SendGetProcessStartInfo() at Appccelerate.StateMachine.Machine.ActionHolders.ArgumentLessActionHolder.Execute(Object argument) at Appccelerate.StateMachine.Machine.States.State`2.ExecuteEntryAction(IActionHolder actionHolder, ITransitionContext`2 context)

--- EXCEPTION #1/1 [LoggerException]
Message = “
  Transition failed: Transition from state <HandShake> on event <remote::.ProtocolVersion>.
  Cause: System.InvalidOperationException: Test-cases are missing for the selected tests. Did discovery succeed?
     at JetBrains.ReSharper.UnitTestFramework.DotNetCore.DotNetVsTest.DotNetVsTestExecution.SendGetProcessStartInfo()
     at Appccelerate.StateMachine.Machine.ActionHolders.ArgumentLessActionHolder.Execute(Object argument)
     at Appccelerate.StateMachine.Machine.States.State`2.ExecuteEntryAction(IActionHolder actionHolder, ITransitionContext`2 context)
”
ExceptionPath = Root
ClassName = JetBrains.Util.LoggerException
HResult = COR_E_APPLICATION=80131600
StackTraceString = “
  at JetBrains.ReSharper.UnitTestFramework.DotNetCore.DotNetVsTest.DotNetVsTestProtocol.<.ctor>b__e(Object sender, TransitionExceptionEventArgs`2 args)
     at Appccelerate.StateMachine.Machine.StateMachine`2.RaiseEvent[T](EventHandler`1 eventHandler, T arguments, ITransitionContext`2 context, Boolean raiseEventOnException)
     at Appccelerate.StateMachine.Machine.StateMachine`2.OnExceptionThrown(ITransitionContext`2 context, Exception exception)
     at Appccelerate.StateMachine.Machine.Contexts.TransitionContext`2.OnExceptionThrown(Exception exception)
     at Appccelerate.StateMachine.Machine.States.State`2.HandleException(Exception exception, ITransitionContext`2 context)
     at Appccelerate.StateMachine.Machine.States.State`2.HandleEntryActionException(ITransitionContext`2 context, Exception exception)
     at Appccelerate.StateMachine.Machine.States.State`2.ExecuteEntryAction(IActionHolder actionHolder, ITransitionContext`2 context)
     at Appccelerate.StateMachine.Machine.States.State`2.ExecuteEntryActions(ITransitionContext`2 context)
     at Appccelerate.StateMachine.Machine.States.State`2.Entry(ITransitionContext`2 context)
     at Appccelerate.StateMachine.Machine.States.State`2.EnterShallow(ITransitionContext`2 context)
     at Appccelerate.StateMachine.Machine.States.State`2.EnterHistoryNone(ITransitionContext`2 context)
     at Appccelerate.StateMachine.Machine.States.State`2.EnterByHistory(ITransitionContext`2 context)
     at Appccelerate.StateMachine.Machine.Transitions.Transition`2.Fire(ITransitionContext`2 context)
     at Appccelerate.StateMachine.Machine.States.State`2.Fire(ITransitionContext`2 context)
     at Appccelerate.StateMachine.Machine.StateMachine`2.Fire(TEvent eventId, Object eventArgument)
     at Appccelerate.StateMachine.PassiveStateMachine`2.ProcessQueuedEvents()
     at Appccelerate.StateMachine.PassiveStateMachine`2.Execute()
     at Appccelerate.StateMachine.PassiveStateMachine`2.Fire(TEvent eventId, Object eventArgument)
     at JetBrains.ReSharper.UnitTestFramework.DotNetCore.Channel.DotNetCoreMessageListener.<>c__DisplayClass2`1.<RegisterMessage>b__1(JToken payload)
     at JetBrains.ReSharper.UnitTestFramework.DotNetCore.Channel.DotNetCoreMessageListener.OnMessage(String rawMessage)
     at JetBrains.ReSharper.UnitTestFramework.DotNetCore.Channel.DotNetCoreRemoteChannel.ReaderThreadProc()
     at JetBrains.ReSharper.TaskRunnerFramework.RemoteChannelBase.<Start>b__0(Object _)
     at System.Threading.QueueUserWorkItemCallback.WaitCallback_Context(Object state)
     at System.Threading.ExecutionContext.RunInternal(ExecutionContext executionContext, ContextCallback callback, Object state, Boolean preserveSyncCtx)
     at System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state, Boolean preserveSyncCtx)
     at System.Threading.QueueUserWorkItemCallback.System.Threading.IThreadPoolWorkItem.ExecuteWorkItem()
     at System.Threading.ThreadPoolWorkQueue.Dispatch()
     at System.Threading._ThreadPoolWaitCallback.PerformWaitCallback()
”

2017.08.04 16:58:43.306   ERROR Run: 28147df6-3156-4f24-bd5a-ca737ab6c43a - Faulted
2017.08.04 16:58:43.306   ERROR System.AggregateException: One or more errors occurred. ---> System.InvalidOperationException: Test-cases are missing for the selected tests. Did discovery succeed?
   at JetBrains.ReSharper.UnitTestFramework.DotNetCore.DotNetVsTest.DotNetVsTestExecution.SendGetProcessStartInfo()
   at Appccelerate.StateMachine.Machine.ActionHolders.ArgumentLessActionHolder.Execute(Object argument)
   at Appccelerate.StateMachine.Machine.States.State`2.ExecuteEntryAction(IActionHolder actionHolder, ITransitionContext`2 context)
   --- End of inner exception stack trace ---
   at JetBrains.ReSharper.UnitTestFramework.Launch.Stages.RunTestsStage.<>c__DisplayClassc.<StartSingleRun>b__8()
---> (Inner Exception #0) System.InvalidOperationException: Test-cases are missing for the selected tests. Did discovery succeed?
   at JetBrains.ReSharper.UnitTestFramework.DotNetCore.DotNetVsTest.DotNetVsTestExecution.SendGetProcessStartInfo()
   at Appccelerate.StateMachine.Machine.ActionHolders.ArgumentLessActionHolder.Execute(Object argument)
   at Appccelerate.StateMachine.Machine.States.State`2.ExecuteEntryAction(IActionHolder actionHolder, ITransitionContext`2 context)<---

2017.08.04 16:58:43.306   TRACE Processed message 'ProtocolVersion'
2017.08.04 16:58:43.306    INFO RunTestsStage completed
2017.08.04 16:58:43.307    INFO Finishing run
2017.08.04 16:58:43.316    INFO Run is finished

我的Nuget导入如下:

<ItemGroup>
  <PackageReference Include="Microsoft.Extensions.DependencyModel" Version="1.1.2" />
  <PackageReference Include="Microsoft.NET.Test.Sdk" Version="15.0.0" />
  <PackageReference Include="Microsoft.NETCore.Portable.Compatibility" Version="1.0.1" />
  <PackageReference Include="System.Runtime.InteropServices.WindowsRuntime" Version="4.3.0" />
  <PackageReference Include="System.ServiceModel.Http" Version="4.3.0" />
  <PackageReference Include="xunit" Version="2.2.0" />
  <PackageReference Include="xunit.runner.console" Version="2.2.0" />
</ItemGroup>

1
我在使用Visual Studio 2017/15.3.0,Resharper 2017.1.3和 .Net Core 2.0时,仍然遇到以下问题。这个问题是在升级到 .Net Core 2.0之后开始出现的。 - Bassebus
2
我也遇到了同样的问题,使用 VS2017 v15.3R# 2017.2 EAP12,目标为.NET Core 2.0 - Seany84
@Bassebus 你可以尝试使用预发布版 https://www.nuget.org/packages/xunit.runner.console/2.3.0-beta4-build3742 - BanksySan
我也遇到了与@Seany84相同的问题,使用的是VS2017 15.3和R# 2017.2 EAP12。看起来这是一个独立于上面原始问题的问题。 - Adam Rodger
@BanksySan 谢谢你的提示,我尝试将所有软件包升级到预发布版本,但仍然无法正常工作。我想我应该向Jetbrains支持团队寻求帮助。 - Bassebus
@Bassebus 好的,我认为那是最好的选择。他们甚至可能有支持它的EAP。如果你找到了解决方案,请告诉我们。 - BanksySan
3个回答

10
我的错误在于选择导入的Nuget包。
而不是:
<PackageReference Include="xunit.runner.console" Version="2.2.0" />

我应该有:

<PackageReference Include="xunit.runner.visualstudio" Version="2.2.0" />

在此之后,您可能需要重新构建或关闭并重新打开Visual Studio。


1
对于.NET Core(2.x),只需添加最新的xunit.runner.visualstudio NuGet软件包即可。 - Skorunka František

1
对我来说,我的xUnit测试无法在.NET Core 2.0测试项目中运行的原因完全不同。我看到的错误如下:
Transition failed: Transition from state <HandShake> on event <remote::.ProtocolVersion>

并且

Cause: System.InvalidOperationException: Test-cases are missing for the selected tests. Rebuild the project and try again.

这是由于测试类构造函数中的一些错误代码引起的(我正在为.NET Core 2.0连接一些用户机密信息)。一旦修复了这些代码,我就能够从ReSharper测试运行程序中运行测试。


1

将 Resharper 升级到最新版本(2020.2)有助于我运行测试,没有任何跳过的内容。


网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接