1

I want to move from MSTest to XUnit and installed the following VS extentions

enter image description here

I can write facts and run my tests successfully, but for some reason Assert is unrecognised

enter image description here

5
  • Have you actually added xunit to your project from NuGet? Commented Jan 18, 2016 at 13:09
  • Yes xunit 2.0.0 is installed Commented Jan 18, 2016 at 13:34
  • Yes version 2.1.0 is installed Commented Jan 18, 2016 at 13:38
  • And for the last get-the-simple-stuff-out-of-the-way question, you have using Xunit; in the file? Commented Jan 18, 2016 at 14:20
  • The VS extension is deprecated, see xunit.github.io/docs/… Commented Jan 19, 2016 at 4:53

2 Answers 2

3

I don't have any XUnit extensions installed. Instead I installed these packages from NuGet into my Test library.

  • xunit
  • xunit.runner.visualstudio

Giving:

enter image description here

And a packages.config of:

<?xml version="1.0" encoding="utf-8"?>
<packages>
  <package id="xunit" version="2.1.0" targetFramework="net451" />
  <package id="xunit.abstractions" version="2.0.0" targetFramework="net451" />
  <package id="xunit.assert" version="2.1.0" targetFramework="net451" />
  <package id="xunit.core" version="2.1.0" targetFramework="net451" />
  <package id="xunit.extensibility.core" version="2.1.0" targetFramework="net451" />
  <package id="xunit.extensibility.execution" version="2.1.0" targetFramework="net451" />
  <package id="xunit.runner.visualstudio" version="2.1.0" targetFramework="net451" />
</packages>

Then I created a class:

using Xunit;

public class FunFacts
{
    [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;
    }
}

The tests then passed and failed as expected.

Steps taken from the XUnit - Getting Started Page.

Sign up to request clarification or add additional context in comments.

Comments

2

I followed all the advice that was given in the comments and answers provided and made sure that the following was done

  • The xunit nuget package is installed
  • The xunit.runner.visualstudio is installed
  • The using statement for the xunit library is added

I noticed that the nuget packages was not on the latest version available, so I updated to the latest available versions which resolved the issue.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.