How to fix: NUnit unit tests not showing up in testing pad in Visual Studio Community (Mac)

前端 未结 3 845
不知归路
不知归路 2021-01-21 22:47

In spite of adding NUnit from NuGet to an existing .Net Core project, no unit tests are being shown in the Test Pad.

Note: I posted these images as links because I have

3条回答
  •  滥情空心
    2021-01-21 23:15

    There are multiple requirements of that project, so that VS for Mac can identify and execute the test cases.

    1. The project must be a console application of .NET Core.
    2. The project must have a reference of Microsoft.NET.Test.Sdk (required by VSTest infrastructure).
    3. The project must have a reference of NUnit.
    4. The project must have a reference of NUnit3TestAdapter (required by VSTest infrastructure).

    Example,

    
    
      
        Exe
        netcoreapp2.2
      
    
      
        
        
        
      
    
    

    Note that VS for Windows and VS for Mac (and JetBrains Rider) all use VSTest for unit testing, so this setup works for all such IDEs.

    Also note that if you didn't create this console project from dotnet new nunit, but a normal console application template, you need to manually delete the Main method.

提交回复
热议问题