【问题标题】:visual studio 2015 doesn't see my xunit testsVisual Studio 2015 看不到我的 xunit 测试
【发布时间】:2015-05-29 11:30:00
【问题描述】:

尝试将 xunit 测试添加到我的 ASP.NET 5 项目中,我添加了一个类库并像这样填充 project.json:

{
  "version": "1.0.0-*",
  "description": "",
  "authors": [ "" ],
  "tags": [ "" ],
  "projectUrl": "",
  "licenseUrl": "",

  "dependencies": {
    "xunit": "2.1.0-beta2-build2981",
    "xunit.runner.visualstudio": "2.1.0-beta2-build1055"
  },
  "commands": {
    "test": "xunit.runner.visualstudio"
  },
  "frameworks": {
    "dnx451": { },
    "dnxcore50": {
      "dependencies": {
        "System.Collections": "4.0.10-beta-22816",
        "System.Linq": "4.0.0-beta-22816",
        "System.Threading": "4.0.10-beta-22816",
        "Microsoft.CSharp": "4.0.0-beta-22816"
      }
    }
  }
}

但 Visual Studio 无法识别我在测试资源管理器中的任何单元测试:

public class Class1
{
    [Fact]
    public void PassingTest()
    {
        Assert.Equal(4, Add(2, 2));
    }

    [Fact]
    public void FailingTest()
    {
        Assert.Equal(5, Add(2, 2));
    }

    int Add(int x, int y)
    {
        return x + y;
    }
}

我错过了什么?

【问题讨论】:

  • 您使用的是什么 VS 版本以及什么运行时 (DNX/KRE)?

标签: asp.net-core visual-studio-2015 xunit.net


【解决方案1】:

我今天也遇到了同样的问题。这个解决方案对我有用:

"dependencies": {
    "xunit": "2.1.0-beta3-*",
    "xunit.runner.dnx": "2.1.0-beta3-*",
    "xunit.runner.visualstudio": "2.1.0",
    "xunit.runners": "2.0.0"
  },
"commands": {
    "test": "xunit.runner.dnx"
  },

希望对您有所帮助。我必须安装 3 个 nuget 包:xunit、xunit.runner.visualstudio 和 xunit.runners

【讨论】:

  • 我花了很长时间(事实上直到我重读the documentation)才发现你使用的“命令”行。哇!
【解决方案2】:

使用 aspnet runner beta4 对我有用:
project.json

{
    ...
    "dependencies": {
        "xunit.runner.aspnet": "2.0.0-beta4"
    },
    "commands": {
        "test": "xunit.runner.aspnet"
    },
    ...
}

【讨论】:

  • 不会出现在智能感知中 :(
  • 对我不起作用,即使是最新的 2.1.0-beta1-build60 ;我已经在测试项目和 webapp 项目中尝试过......
  • 你用的是最新的 VS 2015 RC 吗?你有登录测试控制台吗?
  • 是的,最新的。跟踪是:无法启动 Microsoft.Framework.TestHost
  • 你应该在 GitHub 上打开一个问题
【解决方案3】:

你应该尝试一个稳定的,而不是测试版的 xunit 库。

【讨论】:

    【解决方案4】:

    在另一台计算机上,这正在运行http://xunit.github.io/docs/getting-started-dnx.html

    可能是安装问题...感谢来自火星的 agua

    【讨论】:

    • 链接的文档不可用。答案太笼统,没有用,对我没有帮助。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2016-03-10
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2016-05-08
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多