_From @luktar on December 21, 2017 18:25_
VScode version: 1.19
OS: Mac OS X Hight Sierra
Similar https://github.com/OmniSharp/omnisharp-vscode/issues/1292
XUnit code lens appears in the project like workspace (one project only - csproj on top level).
XUnit code lens does not appear in the solution like workspace (sln on a top level, projects inside folders).
Steps to reproduce:
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFramework>netcoreapp2.0</TargetFramework>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="15.5.0" />
<PackageReference Include="xunit" Version="2.3.1" />
<DotNetCliToolReference Include="dotnet-xunit" Version="2.3.1" />
<PackageReference Include="xunit.runner.visualstudio" Version="2.3.1" />
</ItemGroup>
</Project>
_Copied from original issue: Microsoft/vscode#40666_
@luktar: Your experience is expected because your repro steps never actually add the test project into the solution file you created. From the directory containing the solution, you need to use dotnet sln add Test/Test.csproj to add the project to the solution.
I'm adding projects to solutions this way in most cases.
The code lens for xunit works properly on my mac and windows but I updated VSCode to the latest version.
Sorry, I'm slightly confused. Do you mean that the repro steps you provided are incomplete and you still see the issue if you add classlib to your solution after step 3 above?
Hello @DustinCampbell . I mean that I forgot to add a step with adding a test project to the solution.
Everything is working fine!
I don't know the reason what was wrong.
I've made small research and I tried to reproduce exact environment for not showing code leans descriptions for tests. I had two solution types in one directory. I can't edit test description, so I've made new below:
Create new ConsoleApplication in regular .Net (I used 4.6.1) by Visual Studio 2017 in directory X.
Create solution dotnet new sln -n CodeLensTest
mkdir Test, cd ./Testdotnet new classlibdotnet sln ../CodeLensTest.sln add ./test.csproj./Test/Class1.csusing System;
using Xunit;
namespace test
{
public class Class1
{
[Fact]
public void Test1()
{
}
}
}
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFramework>netcoreapp2.0</TargetFramework>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="15.5.0" />
<PackageReference Include="xunit" Version="2.3.1" />
<DotNetCliToolReference Include="dotnet-xunit" Version="2.3.1" />
<PackageReference Include="xunit.runner.visualstudio" Version="2.3.1" />
</ItemGroup>
</Project>
Build project cd .. dotnet build CodeLensTest.sln
In VSCode open workspace on .Test/test.csproj level, open test class - code lens appears.
./CodeLensTest.sln level, open test class - code lens doesn't appear.In step 10 VSCode shows code lens!
csproj level:
sln level:
Glad to see that everything is working properly. Thanks for following up!
Just found this - I can create the issue.
Using @luktar example above - if you create a second project test2, identical in other respects, then add test and test2 to a workspace, only "test" project will have any CodeLens, "test2" will not show any codelens (not even references).


Incidentally if you open the solution instead of add the two folders to workspace, test2 has references in code lens, but no test functionality.
Most helpful comment
Glad to see that everything is working properly. Thanks for following up!