9

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

Timothy G.
  • 6,335
  • 7
  • 30
  • 46
Carol
  • 163
  • 2
  • 10
  • Just to confirm, the setting.json file you've opened is your user setting (not the global setting), right? That is, it is present in your work folder insider the `.vscode` folder, right? – AzuxirenLeadGuy Apr 01 '23 at 03:47
  • Also, please update your question to include the folder path of your workspace folder, and where the test project is located. – AzuxirenLeadGuy Apr 01 '23 at 03:50

3 Answers3

3

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"

Emre Akdemir
  • 465
  • 3
  • 10
1

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.

AzuxirenLeadGuy
  • 2,470
  • 1
  • 16
  • 27
0

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.

Stewart
  • 17,616
  • 8
  • 52
  • 80