I create a solution from classic .NET Framework Console App template. After that I go to CLI and create an xunit test project kicking off the following commands:
dotnet new -t xunittest
dotnet restore
dotnet test
goes well, test passes.
I preserve the "src" -> "test" folders mapping as it is required with .NET Core as far as I know. After that, I try to add my testing project from within my VS 2015 Update 3 and I receive an error: "The DNX Project System package did not load correctly. The problem may have been caused by a configuration change or by the installation of another extension. You can get more information by examining the file 'path to a file on my local disk'.
I have uploaded the latest two events here.
Here is the content of .json of unit testing project:
{
"version": "1.0.0-*",
"buildOptions": {
"debugType": "portable"
},
"dependencies": {
"System.Runtime.Serialization.Primitives": "4.1.1",
"xunit": "2.1.0",
"dotnet-test-xunit": "1.0.0-rc2-192208-24"
},
"testRunner": "xunit",
"frameworks": {
"netcoreapp1.0": {
"dependencies": {
"Microsoft.NETCore.App": {
"type": "platform",
"version": "1.0.1"
}
},
"imports": [
"dotnet5.4",
"portable-net451+win8"
]
}
}
}
I have .NET Core runtime 1.1 installed. Three days ago I managed to import such a project with exactly the same steps. Today I can't do this.
If I am not mistaken, from my (limited) experience, I found that I could not use xUnit
2.1.0
to test my1.0.1
.NET Core app and had to use2.2.0 preview
I have blogged about ASP.NET Core – MVC xUnit Integration Testing.
In hindsight I had 2 problems:
TL;DR : Snipper from Blog post;
ASP.NET Core – MVC xUnit Integration Testing
Recently I wanted to test my new ASP.NET Core MVC app, so that I can be sure my startup.cs configuration is correct, and especially focusing on the JSON parsing of it.
I straight away run into a few basic stumbling blocks that might help a few people out there!
Test Discovery
The first stumbling block was trying to get the tests discovered at all.
I had to select a test runner and add this to the root of my project.json:
I tried to initially use xunit and dotnet-test-xunit versions 2.1.0 which is the officially released version at the time of writing.
But as this does not support Microsoft.NETCore.App 1.0.1, after a bit off Bing’ing around, I figured out that I need to use "dotnet-test-xunit": "2.2.0-preview2-build1029"
Referencing the MVC Project
The second stumbling block was trying to simply reference the MVC project, in this case, “Taskily”. So I added the following line:
But this was giving me a “runtimes” is an unsupported framework error, which I couldn’t for the life of me figure out. In the end, it turned out to be that because the Taskily project (or at least it was called Taskily in the .sln) actually resided in a folder called WebApplication1 so my solution structure looked like this
The way I got this to compile is
The error message was so not intuitive, and was bugging me for ages!