vstest icon indicating copy to clipboard operation
vstest copied to clipboard

Missing source information (CodeFilePath, LineNumber) in discovered test cases for .NET Core (3.x?) projects with "Full" PDB (instead of "Portable" PDB)

Open pkrukp opened this issue 5 years ago • 7 comments

Description

Hi,

I'm using VsTestConsoleWrapper API to discover test cases.

When the test assembly is compiled to .NET Core (3.x?) and is configured to produce Full PDB instead of default Portable PDB, the discovered TestCase have null CodeFilePath and LineNumber is -1.

After switching to Portable PDB the CodeFilePath and LineNumber are correct.

As you can see in next comment, it looks like a regression, because it works correctly if unit test project targets .net core 2.1

Steps to reproduce

I'm attaching:

Reproduction:

  1. unpack ConsoleApp5, verify unit test projects use Full PDBs, compile
  2. unpack VstestTest, compile
  3. download microsoft.testplatform nuget, unpack
  4. run VstestTest, for example:
D:\dv.scripts\vstest_repro\VstestTest\VstestTest\bin\Debug\VstestTest.exe ^
    D:\dv.scripts\vstest_repro\microsoft.testplatform.16.4.0\tools\net451\Common7\IDE\Extensions\TestPlatform\vstest.console.exe ^
    D:\dv.scripts\vstest_repro\ConsoleApp5\UnitTestProject1\bin\Debug\netcoreapp3.1\Microsoft.VisualStudio.TestPlatform.MSTest.TestAdapter.dll ^
    D:\dv.scripts\vstest_repro\ConsoleApp5\UnitTestProject1\bin\Debug\netcoreapp3.1\UnitTestProject1.dll
  1. observe missing CodeFilePath and incorrect LineNumber in output
  2. modify ConsoleApp5 to use Portable PDB, recompile it, rerun VstestTest, observe correct values

Expected behavior

DisplayName=TestMethod1
CodeFilePath=D:\dv.scripts\vstest_repro\ConsoleApp5\UnitTestProject1\UnitTest1.cs
LineNumber=11

Actual behavior

DisplayName=TestMethod1
CodeFilePath=
LineNumber=-1

Diagnostic logs

I'm attaching:

Environment

I have used vstest from nuget packages microsoft.testplatform.16.4.0 and microsoft.testplatform.16.5.0-preview-20191115-01.

I'm testing this on Windows 10.

pkrukp avatar Dec 19 '19 17:12 pkrukp

It works correctly when tested project targets .net core 2.1 (2.x?) - source information is present for both portable and full PDB. So this looks like a regression.

I may be wrong, but I think I read somewhere about DIA update in .net core 3.x - I may be wrong though.

Attaching

pkrukp avatar Dec 20 '19 10:12 pkrukp

Hello, how is it going? If you have any questions, please ask.

pkrukp avatar Jan 31 '20 10:01 pkrukp

I can confirm this issue as well. Currently, it is a blocker for me. Can anybody help with that?

tobyash86 avatar Feb 12 '20 14:02 tobyash86

@singhsarab @mayankbansal018 any update on this?

tobyash86 avatar Feb 27 '20 09:02 tobyash86

@vritant24 weren't you looking at something similar recently? maybe you have some insight into this?

nohwnd avatar Mar 19 '20 09:03 nohwnd

I'm working on a test logger to use with GitHub Actions and just ran into this issue. Both CodeFilePath and LineNumber are empty for my .net core 3.1 project. I tried setting up a .net core 2.1 and 2.2 project but I'm seeing the issue there too. I found that xunit 2.3.x will give -1 for LineNumber while 2.4.x gives 0, otherwise it's always the same results no matter what combo of packages & sdk I use.

xt0rted avatar Aug 28 '20 01:08 xt0rted

@nohwnd Assigning you also on this one as it seems to be related to #3417 where you are assigned.

Evangelink avatar Aug 01 '22 10:08 Evangelink

I could not repro on 17.6.0 test platform that the source information would switch between collecting and not collecting when changing full or portable pdbs. Collecting source info is off by default (for performance). You can force it by configuration. It is enabled by default when using interactive mode (design mode).

vstest.console.exe MSTest2.dll --listtests -- RunConfiguration.CollectSourceInformation=true

nohwnd avatar May 23 '23 09:05 nohwnd