Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

xunit failing after upgrading to .net core 1.1 #1031

Closed
shababhussain opened this issue Nov 16, 2016 · 34 comments
Closed

xunit failing after upgrading to .net core 1.1 #1031

shababhussain opened this issue Nov 16, 2016 · 34 comments

Comments

@shababhussain
Copy link

shababhussain commented Nov 16, 2016

UPDATE: As suggested by @DemoBytom, Adding reference to "Microsoft.DotNet.InternalAbstractions": "1.0.500-preview2-1-003177" solved the problem.

After upgrading my solution to .net core 1.1 runtime, my visual studio 2015 IDE is throwing following exceptions; Any ideas on when xunit will be compatible with .net 1.1?

Compiling XXXXUnitTest for .NETCoreApp,Version=v1.1

Compilation succeeded.
0 Warning(s)
0 Error(s)

Time elapsed 00:00:01.8052505

Unhandled Exception: System.IO.FileNotFoundException: Could not load file or ass
embly 'Microsoft.DotNet.InternalAbstractions, Version=1.0.0.0, Culture=neutral,
PublicKeyToken=adb9793829ddae60'. The system cannot find the file specified.
at Xunit.Runner.DotNet.Program.GetAvailableRunnerReporters()
at Xunit.Runner.DotNet.Program.Run(String[] args)
at Xunit.Runner.DotNet.Program.Main(String[] args)
SUMMARY: Total: 1 targets, Passed: 0, Failed: 1.

@wmeints
Copy link

wmeints commented Nov 17, 2016

I checked it out and it turns out that you have to add a dependency to your project:

"Microsoft.DotNet.InternalAbstractions": "1.0.0"

Or a element if you're using the RC of VS2017

@RTodorov
Copy link

It works if you add InternalAbstractions 1.0.0 but it should also work with v 1.1.0. This would require a new release, right?

@wmeints
Copy link

wmeints commented Nov 17, 2016

Not that I have noticed. I added it to my project and the tests run just fine.

@RTodorov
Copy link

For me it only works with

"Microsoft.DotNet.InternalAbstractions": "1.0.0"

If I add

"Microsoft.DotNet.InternalAbstractions": "1.1.0"

it gives the error reported on this issue.

@DemoBytom
Copy link

I needed to add version
"Microsoft.DotNet.InternalAbstractions": "1.0.500-preview2-1-003177"
to the project to make the runner work.
Project is targetting
netcoreapp1.1

@shababhussain
Copy link
Author

@wmeints Are the target assemblies built with net core 1.0 or 1.1? Downgrading xunit to use .net core 1.0 results in error "One or more projects are incompatible with .NETCoreApp,Version=v1.0 (win81-x64)"

@shababhussain
Copy link
Author

@DemoBytom Thanks. Adding reference to "Microsoft.DotNet.InternalAbstractions": "1.0.500-preview2-1-003177" solved the problem.

@bradwilson
Copy link
Member

We're retiring dotnet-test-xunit. You should use xunit.runner.visualstudio from 2.2 beta 4 instead (it works for both the CLI and inside Visual Studio).

@shababhussain
Copy link
Author

When I add "xunit.runner.visualstudio": "2.2.0-beta4-build1194" dependency and remove dotnet-test-xunit, I get

Errors in C:\XXXXXUnitTest.xproj
Package Microsoft.TestPlatform.ObjectModel 11.0.0 is not compatible with netcoreapp1.1 (.NETCoreApp,Version=v1.1). Package Microsoft.TestPlatform.ObjectModel 11.0.0 supports:
- net35 (.NETFramework,Version=v3.5)
- portable-net45+win8+wp8+wpa81 (.NETPortable,Version=v0.0,Profile=Profile259)
One or more packages are incompatible with .NETCoreApp,Version=v1.1.

@bradwilson
Copy link
Member

Sorry, I thought you were using the Preview 3 tooling (MSBuild), not the Preview 2.1 tooling (project.json). Stick with dotnet-test-xunit for project.json.

@bradwilson
Copy link
Member

bradwilson commented Nov 17, 2016

This is roughly what you should have for preview 2.1 tooling:

{
  "version": "1.0.0-*",
  "buildOptions": {
    "debugType": "portable"
  },
  "dependencies": {
    "xunit": "2.2.0-beta4-build3444",
    "dotnet-test-xunit": "2.2.0-preview2-build1029"
  },
  "testRunner": "xunit",
  "frameworks": {
    "netcoreapp1.1": {
      "dependencies": {
        "Microsoft.NETCore.App": {
          "type": "platform",
          "version": "1.1.0"
        }
      },
      "imports": [
        "dotnet5.4",
        "portable-net451+win8"
      ]
    }
  }
}
$ dotnet --version
1.0.0-preview2-1-003177

That imports section is not strictly required for xUnit.net, but there are other things you're using where it probably will be useful.

@joergjo
Copy link

joergjo commented Nov 17, 2016

I've updated my project.json to match Brad's sample, but it only works if I add "Microsoft.DotNet.InternalAbstractions": "1.0.0" as well.

Without, xunit fails with 'test-xunit' returned '-532462766' when trying to discover tests in VS2015 using 1.0.0-preview2-1-003177.

@bradwilson
Copy link
Member

I did not test inside Visual Studio, only from the command line.

@DemoBytom
Copy link

Even when running from the console I get
Unhandled Exception: System.IO.FileNotFoundException: Could not load file or assembly 'Microsoft.DotNet.InternalAbstractions, Version=1.0.0.0, Culture=neutral, PublicKeyToken=adb9793829ddae60'. Nie można odnaleźć określonego pliku. at Xunit.Runner.DotNet.Program.GetAvailableRunnerReporters() at Xunit.Runner.DotNet.Program.Run(String[] args) at Xunit.Runner.DotNet.Program.Main(String[] args)

Unless I add
"Microsoft.DotNet.InternalAbstractions": "1.0.500-preview2-1-003177" to the project.json

In Visual Studio the tests are not even discoveried untill the afromentioned line is added.

We're still using tooling from preview 2, we plan to move to preview 3, but I'm not sure when (not my decision :( )

@DemoBytom
Copy link

DemoBytom commented Nov 18, 2016

I narrowed the problem down, a bit. It doesn't break every time, the example bradwilson posted indeed works. But if i add a reference to
"Microsoft.AspNetCore.Mvc.Core": "1.1.0" or
"Microsoft.AspNetCore.Mvc.Core": "1.1.0-preview1-final"- it breaks.

{
  "version": "1.0.0-*",
  "buildOptions": {
    "debugType": "portable"
  },
    "dependencies": {
        "xunit": "2.2.0-beta4-build3444",
        "dotnet-test-xunit": "2.2.0-preview2-build1029",
        "Microsoft.AspNetCore.Mvc.Core": "1.1.0"
    },
  "testRunner": "xunit",
  "frameworks": {
    "netcoreapp1.1": {
        "dependencies": {
            "Microsoft.NETCore.App": {
                "type": "platform",
                "version": "1.1.0"
            }
        },
        "imports": [
            "dotnet5.4",
            "portable-net451+win8"
        ]
    }
  }
}

Removing the line or switching back to "Microsoft.AspNetCore.Mvc.Core": "1.0.1" makes the unit tests discoverable in VS and pass without exceptions in the CMD.
I know there are other .Net Core packages that also make the project fail during dotnet test.

@joergjo
Copy link

joergjo commented Nov 18, 2016

Just to confirm: My project uses ASP.NET Core MVC 1.1.

@radenkozec
Copy link

To confirm adding "Microsoft.DotNet.InternalAbstractions": "1.0.0" to XUnit project solved the problem

@hiiru
Copy link

hiiru commented Nov 18, 2016

I have the same problem and created a reproduction repo here: https://github.com/hiiru/dotnet-test-exception
it has a .NET Core 1.0 branch that works and a .NET Core 1.1 in which "Failing.Test" doesn't work.

the problem is caused by a dependency on Microsoft.Extensions.DependencyModel 1.1.0-*
This dependency is also included in Microsoft.AspNetCore.Mvc.Core, which causes all tests targeting an MVC project will fail.

It's also hard to spot at first because inside visual studio, those tests just disappear, the error is only visible when running it on the console itself.

@epignosisx
Copy link

Adding Microsoft.DotNet.InternalAbstractions was the solution used by the ASP.NET Core MVC test project:

https://github.com/aspnet/Mvc/blob/dev/test/Microsoft.AspNetCore.Mvc.Test/project.json#L9

@bojingo
Copy link

bojingo commented Nov 21, 2016

I kept having issues discovering the tests within Visual Studio's Test Explorer even with Microsoft.DotNet.InternalAbstractions.

I was missing updating the SDK version in the global.json file:

{
  "projects": [ "src", "test" ],
  "sdk": {
    "version": "1.0.0-preview2-1-003177"
  }
}

Microsoft.DotNet.InternalAbstractions in conjunction with the SDK version pointing to the 1.1 SDK tools got everything working.

@bradwilson
Copy link
Member

You should always, always have a global.json file with an SDK version in it.

Always.

@oliverjanik
Copy link

oliverjanik commented May 15, 2017

I can confirm this is still a problem. Even after installing Microsoft.DotNet.InternalAbstractions 1.0.0 I still get:

Package Microsoft.TestPlatform.ObjectModel 11.0.0 is not compatible with netcoreapp1.1 (.NETCoreApp,Version=v1.1). Package Microsoft.TestPlatform.ObjectModel 11.0.0 supports:
  - net35 (.NETFramework,Version=v3.5)
  - portable-net45+win8+wp8+wpa81 (.NETPortable,Version=v0.0,Profile=Profile259)
One or more packages are incompatible with .NETCoreApp,Version=v1.1.

@bradwilson
Copy link
Member

FYI, we no longer officially support project.json-based .NET Core.

@oliverjanik
Copy link

I'm not using project.json I'm just using out of the box .net core library template from VS 2017

@bradwilson
Copy link
Member

Do these instructions not work correctly for you? https://xunit.github.io/docs/getting-started-dotnet-core.html

@oliverjanik
Copy link

They did, I had to upgrade to xunit 2.3.0-beta2-build3683. Comandline dotnet xunit works fine. Hope yo can release 2.3.0 soon.

But I'm getting strange issue with resharper 2017.1.2 it won't run xunit tests from within the UI. It says:
System.InvalidOperationException: Test-cases are missing for the selected tests. Did discovery succeed?

@bradwilson
Copy link
Member

We have no responsibility for the Resharper runner. You should report issues with it to the JetBrains team.

@oliverjanik
Copy link

I've found the issue with the project. xunit 2.2 is ok with netcoreapp1.1 but you have to use the Xunit template provided in VS2017 which includes this nuget (which I was missing): https://www.nuget.org/packages/microsoft.net.test.sdk/15.0.0

That makes it work with Resharper.

Anyway I'm glad the goose chase is over. Thanks for your help, Brad.

@egmfrs
Copy link

egmfrs commented Aug 30, 2017

To summarise; after reading this thread, I had success from adding the following packages:
Microsoft.NET.Test.Sdk (version 15.0.0 or later)
xunit.runner.visualstudio 2.3.0-beta4-build3742 - I struggled to see this at first as I had forgotten to tick "Include pre-releases" in NuGet Package Manager window
I also had to add this manually into the .csproj file:
<PackageReference Include="Microsoft.DotNet.InternalAbstractions" Version="1.0.500-preview2-1-003177" />
Click Run All in the Test Explorer Window - this rebuilds the project, finds the tests and runs them.

@bradwilson
Copy link
Member

There should be no need for the Microsoft.DotNet.InternalAbstractions package. What caused you to add it?

@egmfrs
Copy link

egmfrs commented Aug 30, 2017

@bradwilson the first line in the first comment here suggests it's the solution. So I had added this first. I have removed it now.

I also got it working with xunit.runner.visualstudio 2.2.0.

Not sure why it was previously telling me 2.2.0 was incompatible with netcoreapp 1.1, but after starting a new project and choosing "xUnit Test Project (.NET Core)" it all seemed to work fine without me needing to add or change anything.

@bradwilson
Copy link
Member

2.2.0 should be fine with 1.1.

There were issues related to 2.0 that I attempted to fix in 2.3 beta 4, and actually fixed in 2.3 beta 5 (not yet shipped), that could affect both 1.x and 2.x tests.

@gozineha
Copy link

I have the same problem and created a reproduction repo here: https://github.com/hiiru/dotnet-test-exception
it has a .NET Core 1.0 branch that works and a .NET Core 1.1 in which "Failing.Test" doesn't work.

the problem is caused by a dependency on Microsoft.Extensions.DependencyModel 1.1.0-*
This dependency is also included in Microsoft.AspNetCore.Mvc.Core, which causes all tests targeting an MVC project will fail.
آزمون استخدامی جدید
گزینه ها
It's also hard to spot at first because inside visual studio, those tests just disappear, the error is only visible when running it on the console itself.

@bradwilson
Copy link
Member

Closed for age.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests