8

I have a Class Library (Package) project, the new preview template in VS 2015 RTM from which I want to execute Xunit tests.

The solution builds fine but the Test Explorer doesn't find any tests. From the project.json you can see that I am only targeting net45, not dnx, so I am using xunit.runner.visualstudio.

{
    "dependencies": {
        "myproject": "",
        "xunit": "2.1.0-*",
        "xunit.runner.visualstudio": "2.1.0-*"
    },

    "frameworks": {
        "net45": {
            "frameworkAssemblies": {
                "System.Runtime": "4.0.0.0"
            }
        }
    }
}

When I change the project type to a normal Class Library, the tests are picked up. However since the code I am trying to test is a Class Library (package) project, referencing it from a normal Class Library is problematic and I was hoping that this would work. Is this (or some variation) possible?

Context

Normally this project type is used for ASP.NET 5, Core CLR, etc. Even though I'm only targeting net45, I am using it because I want to take advantage of the feature where I can seamlessly use local source code in place of a nuget package (via the global.json projects attribute). It makes it much easier to work on a package that depends upon another where I'm often making changes in both locally.

  • 1
    I have the same problem and it seems it can't be done right now: http://stackoverflow.com/questions/32619892/how-to-run-xunit-tests-in-the-project-json-and-dotnet-tfm-world – Robert Muehsig Sep 22 '15 at 21:14

1 Answers1

0

If you are running on DNX beta 7.0 than the xUnit declaration in project.json would need to look like this:

"dependencies": {

    "xunit": "2.1.0-rc1-build3168",
    "xunit.runner.dnx": "2.1.0-beta5-build169"
  },
"commands": {

    "test": "xunit.runner.dnx"
  },

and than i hope when you build the project the test will show up. I have the similar problem until i did't use the correct version of xUnit with correct DNX version.

Here is the link where you can read more about the config. of xUnit and ASP.NET 5 http://xunit.github.io/docs/getting-started-dnx.html

I hope I helped.

Domysee
  • 12,718
  • 10
  • 53
  • 84
  • Question : in case I've defined multiple framework in the project.json, how to start xunit from the commandline for a specific framework? dnx --framework dnxcore50 -p test/Hello.Test does not seem to work ? – Stef Heyenrath Apr 29 '16 at 13:37