0

I got the an error while trying to execute my .NET Core 2.0.0 XUnit tests project...

Errors

Using Visual Studio and the dotnet test command

[2018-04-11 22:49:23 Informational] ========== Run test finished: 0 run (0:00:09,154719) ==========
[2018-04-11 22:56:42 Informational] ------ Run test started ------
[2018-04-11 22:56:43 Informational] [xUnit.net 00:00:00.5430826]   Discovering: SolidStack.Core.Guards.Tests
[2018-04-11 22:56:44 Informational] [xUnit.net 00:00:00.6529533]   Discovered:  SolidStack.Core.Guards.Tests
[2018-04-11 22:56:44 Informational] [xUnit.net 00:00:00.7116245]   Starting:    SolidStack.Core.Guards.Tests
[2018-04-11 22:56:52 Error] The active test run was aborted. Reason: .2.0.3545, Culture=neutral, PublicKeyToken=8d05b1bb7a6fdb6c]](<RunTestMethodsAsync>d__38<System.__Canon> ByRef)
   at Xunit.Sdk.TestClassRunner`1[[System.__Canon, System.Private.CoreLib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=7cec85d7bea7798e]].RunTestMethodsAsync()
   at Xunit.Sdk.TestClassRunner`1+<RunAsync>d__37[[System.__Canon, System.Private.CoreLib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=7cec85d7bea7798e]].MoveNext()
   at System.Runtime.CompilerServices.AsyncTaskMethodBuilder`1[[System.__Canon, System.Private.CoreLib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=7cec85d7bea7798e]].Start[[Xunit.Sdk.TestClassRunner`1+<RunAsync>d__37[[System.__Canon, System.Private.CoreLib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=7cec85d7bea7798e]], xunit.execution.dotnet, Version=2.2.0.3545, Culture=neutral, PublicKeyToken=8d05b1bb7a6fdb6c]](<RunAsync>d__37<System.__Canon> ByRef)
   at Xunit.Sdk.TestClassRunner`1[[System.__Canon, System.Private.CoreLib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=7cec85d7bea7798e]].RunAsync()
   at Xunit.Sdk.TestCollectionRunner`1+<RunTestClassesAsync>d__28[[System.__Canon, System.Private.CoreLib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=7cec85d7bea7798e]].MoveNext()
   at System.Runtime.CompilerServices.AsyncTaskMethodBuilder`1[[System.__Canon, System.Private.CoreLib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=7cec85d7bea7798e]].Start[[Xunit.Sdk.TestCollectionRunner`1+<RunTestClassesAsync>d__28[[System.__Canon, System.Private.CoreLib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=7cec85d7bea7798e]], xunit.execution.dotnet, Version=2.2.0.3545, Culture=neutral, PublicKeyToken=8d05b1bb7a6fdb6c]](<RunTestClassesAsync>d__28<System.__Canon> ByRef)
   at Xunit.Sdk.TestCollectionRunner`1[[System.__Canon, System.Private.CoreLib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=7cec85d7bea7798e]].RunTestClassesAsync()
   at Xunit.Sdk.TestCollectionRunner`1+<RunAsync>d__27[[System.__Canon, System.Private.CoreLib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=7cec85d7bea7798e]].MoveNext()
   at System.Runtime.CompilerServices.AsyncTaskMethodBuilder`1[[System.__Canon, System.Private.CoreLib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=7cec85d7bea7798e]].Start[[Xunit.Sdk.TestCollectionRunner`1+<RunAsync>d__27[[System.__Canon, System.Private.CoreLib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=7cec85d7bea7798e]], xunit.execution.dotnet, Version=2.2.0.3545, Culture=neutral, PublicKeyToken=8d05b1bb7a6fdb6c]](<RunAsync>d__27<System.__Canon> ByRef)
   at Xunit.Sdk.TestCollectionRunner`1[[System.__Canon, System.Private.CoreLib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=7cec85d7bea7798e]].RunAsync()
   at Xunit.Sdk.XunitTestAssemblyRunner+<>c__DisplayClass14_2.<RunTestCollectionsAsync>b__3()
   at System.Threading.Tasks.Task`1[[System.__Canon, System.Private.CoreLib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=7cec85d7bea7798e]].InnerInvoke()
   at System.Threading.ExecutionContext.Run(System.Threading.ExecutionContext, System.Threading.ContextCallback, System.Object)
   at System.Threading.Tasks.Task.ExecuteWithThreadLocal(System.Threading.Tasks.Task ByRef)
   at System.Threading.Tasks.Task.ExecuteEntry()
   at System.Threading.Tasks.SynchronizationContextTaskScheduler+<>c.<.cctor>b__8_0(System.Object)
   at Xunit.Sdk.MaxConcurrencySyncContext.RunOnSyncContext(System.Threading.SendOrPostCallback, System.Object)
   at System.Threading.ExecutionContext.Run(System.Threading.ExecutionContext, System.Threading.ContextCallback, System.Object)
   at Xunit.Sdk.MaxConcurrencySyncContext.WorkerThreadProc()
   at Xunit.Sdk.XunitWorkerThread+<>c.<QueueUserWorkItem>b__5_0(System.Object)
   at System.Threading.ExecutionContext.Run(System.Threading.ExecutionContext, System.Threading.ContextCallback, System.Object)
   at System.Threading.Tasks.Task.ExecuteWithThreadLocal(System.Threading.Tasks.Task ByRef)
   at System.Threading.ExecutionContext.Run(System.Threading.ExecutionContext, System.Threading.ContextCallback, System.Object)

[2018-04-11 22:56:52 Informational] ========== Run test finished: 0 run (0:00:09,5410612) ==========

Config

[Project].Tests.csproj

<Project Sdk="Microsoft.NET.Sdk">

  <PropertyGroup>
    <TargetFramework>netcoreapp2.0</TargetFramework>

    <IsPackable>false</IsPackable>
  </PropertyGroup>

  <ItemGroup>
    <PackageReference Include="FluentAssertions" Version="5.0.0-beta0003" />
    <PackageReference Include="Microsoft.NET.Test.Sdk" Version="15.3.0-preview-20170628-02" />
    <PackageReference Include="xunit" Version="2.2.0" />
    <PackageReference Include="xunit.runner.visualstudio" Version="2.2.0" />
  </ItemGroup>

  <ItemGroup>
    <ProjectReference Include="..\SolidStack.Core.Guards\SolidStack.Core.Guards.csproj" />
  </ItemGroup>

  <ItemGroup>
    <Service Include="{82a7f48d-3b50-4b1e-b82e-3ada8210c358}" />
  </ItemGroup>

</Project>

The exact same config works perfectly in an other project.

Am I doing something wrong?

Maxime Gélinas
  • 2,202
  • 2
  • 18
  • 35
  • I deleted my previous answer as it was plain wrong. – Mickaël Derriey Apr 12 '18 at 03:21
  • 1
    You seem to use `dotnet test` against the wrong project as it's the project that is being referenced by your test project, not the test project itself. – Mickaël Derriey Apr 12 '18 at 03:21
  • Oh god you're totally right! But why it's not working inside Visual Studio? – Maxime Gélinas Apr 12 '18 at 04:07
  • I don't know, but I can suggest two things: 1) delete the VS test explorer cache as instructed [in the xUnit documentation](http://xunit.github.io/docs/getting-started-desktop#run-tests-visualstudio). 2) Try to update the NuGet packages to their latest versions - I know xUnit are now up to `2.3.1` IIRC. – Mickaël Derriey Apr 12 '18 at 05:34
  • @MickaëlDerriey I edited my question based on your comment about wrong project name in the `dotnet test` command. Now I have the same error from visual studio and the `dotnet test` command. Deleting the VS test explorer cache and updatind the packages versions didn't fix the issue. – Maxime Gélinas Apr 12 '18 at 20:52
  • Can you try creating a brand new .NET Core solution with a .NET Core xUnit test project (use the VS template) and try to run the tests? – Mickaël Derriey Apr 13 '18 at 00:38
  • @MickaëlDerriey I answered my own question, but thanks anyway! – Maxime Gélinas Apr 13 '18 at 01:29

1 Answers1

1

The error was caused by the code itself more specifically by the use of the Debug.Assert () / Debug.Fail () methods which causes some sort of error which is apparently not handled by xunit.

Maxime Gélinas
  • 2,202
  • 2
  • 18
  • 35