xamarinstudio.xunit icon indicating copy to clipboard operation
xamarinstudio.xunit copied to clipboard

Please uninstall this extension as Visual Studio for Mac/MonoDevelop natively supports xUnit.net now

Open lextm opened this issue 7 years ago • 6 comments

Microsoft announced VSTest support in Visual Studio for Mac 7.3,

https://blogs.msdn.microsoft.com/visualstudio/2017/12/04/visual-studio-2017-version-15-5-visual-studio-for-mac-released/

Visual Studio Test Platform (VSTest) support. Visual Studio for Mac now supports a wider variety of test frameworks through the integration of VSTest, giving developers more choice in the test frameworks they want to use. Frameworks such as MSTest or xUnit can now be used within Visual Studio for Mac via NuGet adapter packages.

This marks the end of this separate extension to hook xUnit.net with VS for Mac.

Please uninstall this extension and enjoy the built-in support.

lextm avatar Dec 05 '17 01:12 lextm

MonoDevelop 7 ships the same VSTest integration, so no other extension is needed either.

lextm avatar Dec 14 '17 21:12 lextm

How to make Visual Studio for Mac see tests without this plugin, if my project is for Mono? It seems to see them only for .NET Core.

usr-sse2 avatar Feb 07 '18 13:02 usr-sse2

@usr-sse2, you could try this:

  1. Add new tests project of type .NET Core / Tests / xUnit Tests Project.
  2. Move your test classes to the new project.
  3. Reference your non- .NET Standard project in the tests .csproj manually:
<ItemGroup>
   <ProjectReference Include="..\YourBaseProject\YourBaseProject.csproj" />
</ItemGroup>

This works for me on Mono 5.10 and MonoDevelop 7.4 with only few quirks, like the рroject reference displayed with error "Incompatible target framework..."

More safe approach would be to move all your code which should be testable into the separate .NET Standard 2.0 library project. Then you could reference it in the tests project (which is .NET Core) and in the main project (could be full .NET Framework or Mono or .NET Core). But this will have ts drawbacks - more projects/assemblies to manage, sometimes need major code rework to ensure testability w/o referencing something outside .NET Standard like WPF or WebForms.

roman-yagodin avatar Mar 13 '18 20:03 roman-yagodin

@usr-sse2 You need to add a few NuGet packages, including xUnit Visual Studio runner. Make sure Visual Studio 2017 can discover the test cases, and then Visual Studio for Mac and MonoDevelop 7.x on Linux should do the same.

@roman-yagodin I have no problem running Mono based projects. There seems to be no need to convert to .NET Standard projects.

lextm avatar Mar 14 '18 03:03 lextm

@lextm You need to add a few NuGet packages, including xUnit Visual Studio runner

Seems like just adding xunit.runner.visualstudio package fixed my tests discovery issues with MonoDevelop 7.4 w/o converting projects to .NET Core / .NET Standard - my thanks!

My packages.config file:

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

roman-yagodin avatar Mar 14 '18 06:03 roman-yagodin

It оказалось, that Visual Studio for Mac doesn’t find XUnit tests if both XUnit and NUnit are referenced in the same project. Removing NUnit reference fixed the problem.

usr-sse2 avatar Mar 14 '18 06:03 usr-sse2