7

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.

4

1 回答 1

0

如果您在 DNX beta 7.0 上运行,则 project.json 中的 xUnit 声明需要如下所示:

"dependencies": {

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

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

而且我希望当您构建项目时,测试会出现。在我没有使用正确版本的 xUnit 和正确的 DNX 版本之前,我遇到了类似的问题。

这是链接,您可以在其中阅读有关配置的更多信息。xUnit 和 ASP.NET 5 http://xunit.github.io/docs/getting-started-dnx.html

我希望我有所帮助。

于 2015-11-06T13:57:35.703 回答