Omnisharp-vscode: XUnit code lens (run test, debug test) not appear in solution workspace

Created on 21 Dec 2017  路  6Comments  路  Source: OmniSharp/omnisharp-vscode

_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:

  1. Create solution 'dotnet new sln'
  2. Create test folder 'mkdir Test', 'cd ./Test'
  3. Create test project 'create classlib'
  4. Put this to csproj
<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>
  1. Open workspace on csproj level, open test class - code lens appears.
  2. Open workspace on sln level, open test class - code lens doesn't appear.

_Copied from original issue: Microsoft/vscode#40666_

Resolved-By Design Test

Most helpful comment

Glad to see that everything is working properly. Thanks for following up!

All 6 comments

@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:

  1. Create new ConsoleApplication in regular .Net (I used 4.6.1) by Visual Studio 2017 in directory X.

  2. Create solution dotnet new sln -n CodeLensTest

  3. Create test folder mkdir Test, cd ./Test
  4. Create test project dotnet new classlib
  5. Add project to solution dotnet sln ../CodeLensTest.sln add ./test.csproj
  6. Add this code to ./Test/Class1.cs
using System;
using Xunit;

namespace test
{
    public class Class1
    {
        [Fact]
        public void Test1()
        {

        }
    }
}
  1. Put this to csproj
<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>
  1. Build project cd .. dotnet build CodeLensTest.sln

  2. In VSCode open workspace on .Test/test.csproj level, open test class - code lens appears.

  3. In another window of VSCode open workspace on ./CodeLensTest.sln level, open test class - code lens doesn't appear.

In step 10 VSCode shows code lens!

csproj level:

csprop level

sln 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).

image

image

Incidentally if you open the solution instead of add the two folders to workspace, test2 has references in code lens, but no test functionality.

Was this page helpful?
0 / 5 - 0 ratings