Running xUnit on Visual Studio for Mac
Asked Answered
S

5

15

I am currently evaluating Visual Studio for Mac. And I ran into a little problem. It won't detect any of my xUnit unit tests. On the Windows version of VS, the tests are automatically picked up when I click on "Run all Tests". But with this version, it's not. Are there any instructions on how to setup xUnit to work inside Visual Studio for Mac?

Thanks for the help! ;0)

S answered 30/11, 2016 at 5:4 Comment(0)
S
15

[Update: 2018-04-11]

Visual Studio for Mac now has built-in support for xUnit.

[Original Post]

Ok, so for anyone searching for this. Basically Visual Studio for Mac is not currently compatible with xUnit. I spoke to the xUnit core team, and they have no plans on supporting Visual studio for Mac. You can follow the conversation HERE. I also spoke to the xamarinstudio.xunit plugin team. And they said that they are planning on supporting it if VS for Mac doesn't out of the box. But that we will have to wait a little bit to see what the requirements are. You can follow the conversation HERE

S answered 7/12, 2016 at 2:22 Comment(0)
T
11

Visual Studio for Mac now has a built in support for xUnit (Just create a new project in your solution, and under the .NET Core project type you'll see a Tests project that you can add and write tests with)

Let me know if this worked out for you

Tuatara answered 15/5, 2017 at 13:26 Comment(2)
Nice Jonathan!... I'll have to test it tonight. Thanks for the info! :)S
I tried. I met the exception "Unable to run tests. Test discovery failed.".Bozeman
F
2

Version 2.3.1 of xUnit seemed to solve a lot of issues I had both with Live Unit testing in VS2017 and some issues with VS for Mac as well.

Fecteau answered 31/10, 2017 at 23:20 Comment(0)
I
0

With the latest version of VS for mac (7.1) With .Net Core 2.0 support - you can now run the tests and see them in the "Test Results" window, available in the BRHS of the IDE.

You will need to select the project from the top left hand drop down - ensure that it is: " - Unit tests"

You can then run using the Run button and the results will be displayed in the window above.

Inefficient answered 16/8, 2017 at 17:41 Comment(0)
H
0

I had similar issue

This was my old .csproj

  <ItemGroup>
    <PackageReference Include="xunit" Version="2.4.1" />
    <PackageReference Include="xunit.runner.visualstudio" Version="2.4.3">
        <IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
        <PrivateAssets>all</PrivateAssets>
    </PackageReference>

and I added Microsoft.NET.Test.Sdk

  <ItemGroup>
    <PackageReference Include="Microsoft.NET.Test.Sdk" Version="16.5.0" />
    <PackageReference Include="xunit" Version="2.4.1" />
    <PackageReference Include="xunit.runner.visualstudio" Version="2.4.3">
        <IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
        <PrivateAssets>all</PrivateAssets>
    </PackageReference>

That made test discovery working again.

Another thought: removing and re-adding packages should pull in correct packages (maybe).

Hermosillo answered 29/8, 2021 at 10:54 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.