Not able to use XUnit for unit tests in ASP.NET VNext and Visual Studio 2015 RC

妖精的绣舞 提交于 2020-01-02 16:08:21

问题


I created a a Visual Studio 2015 RC solution as follows:

Project
  global.json
Source
  MvcProject
  MvcProject.Test

MvcProject.Test is a class library where I created a Test.

The global.json file has the following:

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

And project.json in MvcProject.Test is:

{
  "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"
      }
    }
  }
}

I then created a simple test:

using Xunit;

namespace MvcProject.Test {
  public class FirstTests {

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

  }
}

When I build the solition I get the error:

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  

What am I missing in my configuration?


回答1:


This blog post works with RTM. Please leave comments on the blog if you have any problems.




回答2:


There is a guide for it here I followed it and works perfectly.

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



来源:https://stackoverflow.com/questions/31121523/not-able-to-use-xunit-for-unit-tests-in-asp-net-vnext-and-visual-studio-2015-rc

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!