【问题标题】:Not able to use XUnit for unit tests in ASP.NET VNext and Visual Studio 2015 RC无法在 ASP.NET VNext 和 Visual Studio 2015 RC 中使用 XUnit 进行单元测试
【发布时间】:2015-06-29 17:05:50
【问题描述】:

我创建了一个 Visual Studio 2015 RC 解决方案,如下所示:

Project
  global.json
Source
  MvcProject
  MvcProject.Test

MvcProject.Test 是一个类库,我在其中创建了一个测试。

global.json 文件有以下内容:

{
  "projects": [ "Source" ],
  "sdk": {
    "version": "1.0.0-beta4"
  }
}    

而 MvcProject.Test 中的 project.json 是:

{
  "compilationOptions": {
    "warningsAsErrors": true
  },
  "dependencies": {
    "Microsoft.AspNet.Mvc": "6.0.0-*",
    "xunit.runner.aspnet": "2.0.0-aspnet-*"
  },
  "commands": {
    "test": "xunit.runner.aspnet"
  },
  "frameworks": {
    "dnx451": {
      "dependencies": {
        "Moq": "4.2.1506.2016"
      }
    }
  }
}

然后我创建了一个简单的测试:

using Xunit;

namespace MvcProject.Test {
  public class FirstTests {

    [Fact]
    public void HelloTest() {
      Assert.Equal(2, 2);
    }

  }
}

当我构建 solition 时出现错误:

The type or namespace name 'Fact' could not be found (are you missing a using directive or an assembly reference?)  MvcProject.Test.DNX 4.5.1   

The name 'Assert' does not exist in the current context Bityond.Test.DNX 4.5.1  

我的配置中缺少什么?

【问题讨论】:

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


    【解决方案1】:

    blog post 与 RTM 一起使用。有任何问题请在博客上留言。

    【讨论】:

      【解决方案2】:

      这里有一个指南,我按照它并完美运行。

      http://xunit.github.io/docs/getting-started-dnx.html

      【讨论】:

      • 不再适用于 Visual Studio 2015 的发行版,但看起来足够聪明,并且坚持不懈,可以找出问题所在并修复它。
      • 我去看看最近我的 vnext 项目没有工作所以没注意到。
      • 我遇到了控制台 dnx 运行器和 visualstudio 运行器都不再工作的问题。例如"commands": { "test": "xunit.runner.dnx" },不提供IDE集成,也不从命令行运行
      • 我想通了并做了一个有效的演示。 bitbucket.org/wpostma/aspnet5mvc6xunitdemo
      猜你喜欢
      • 2017-04-11
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2015-10-22
      • 1970-01-01
      • 2016-03-10
      • 2017-08-13
      • 2018-09-23
      相关资源
      最近更新 更多