Test not found in .NET Test Explorer Extension for VS Code

2.5k views Asked by At

I can not see my tests in .NET Test Explorer Extension. I've already configured settings.json

{
    "dotnet-test-explorer.testProjectPath": "**/*ComprasPrevidencia/ComprasPrevidencia.csproj",
    "dotnet-test-explorer.autoWatch": true,
    "dotnet-test-explorer.runInParallel": true 
}

At terminal I search for avaible tests with success:

dotnet test -t -v=q

Os Testes a seguir estão disponíveis: Acumulacao AcumulacaoRisco Risco

My .csproj:

<Project Sdk="Microsoft.NET.Sdk">
  <PropertyGroup>
    <TargetFramework>netcoreapp3.1</TargetFramework>
    <IsPackable>false</IsPackable>
  </PropertyGroup>
  <ItemGroup>
     <PackageReference Include="nunit" Version="3.12.0"/>
     <PackageReference Include="NUnit3TestAdapter" Version="3.15.1"/>
     <PackageReference Include="Microsoft.NET.Test.Sdk" Version="16.4.0"/>
     <PackageReference Include="Selenium.WebDriver" Version="3.141.0"/>
     <PackageReference Include="Selenium.Support" Version="3.141.0"/>
     <PackageReference Include="Selenium.WebDriver.ChromeDriver" Version="85.0.4183.8700"/>
     <PackageReference Include="ClosedXML_Excel" Version="1.0.0"/>
     <PackageReference Include="ClosedXML" Version="0.95.3"/>
     <PackageReference Include="SQL" Version="1.0.5075.31045"/>
    <PackageReference Include="System.Data.SqlClient" Version="4.5.1" />
 </ItemGroup>
</Project>

The VSCode

3

There are 3 answers

0
Stewart On

I believe I have found the problem + solution.

In class

Acme/Test/AcmeTests.cs

There was a reference to a class

Acme/Acme.cs

but no corresponding

using Acme;

Also

Acme/Acme.Tests.csproj

Needed

<ItemGroup>
    <ProjectReference Include="..\Acme\Acme.csproj" />
</ItemGroup>

I think VS Code was not complaining about this, because these 2 .csproj files were not part of .sln

Regardless, ALL tests were not being found because of this one broken test config. Once fixed, VS Code was able to find all the tests.

0
AzuxirenLeadGuy On

I feel that the property "dotnet-test-explorer.testProjectPath" expects the relative path of the parent folder of the required csproj file. This has always worked for me. The extension scans the folder for all csproj files within the matched path and finds the required project(s) that contain unit tests.

So, if your working directory looks like this

.
├── MyCoreLib
│   ├── MyCoreLib.csproj
│   └── Lib.cs
├── SomeOtherProj
│   ├── SomeOtherProj.csproj
│   └── OtherProjFile.cs
└── MyTestLib
    ├── MyTestLib.csproj
    └── UnitTests.cs

Here, the path of the parent folder of the test project is MyTestLib/, so the user setting file (contained within .vscode/setting.json) should contain

{
    "dotnet-test-explorer.testProjectPath": "MyTestLib/" 
    // Relative path of parent folder only
}

And with that, the extension should work properly.

0
Emre Akdemir On

It may be a similar topic. It appears to be resolved in the following way.

Reference Answer

workaround: change the tree view to "flat"

update settings.json with "dotnet-test-explorer.treeMode": "flat"