Skip to content

Derive line numbers from source in DiscoverTestsUsingSourceNavigation#15524

Closed
nohwnd wants to merge 1 commit intomicrosoft:mainfrom
nohwnd:fix/15448-source-nav-line-numbers
Closed

Derive line numbers from source in DiscoverTestsUsingSourceNavigation#15524
nohwnd wants to merge 1 commit intomicrosoft:mainfrom
nohwnd:fix/15448-source-nav-line-numbers

Conversation

@nohwnd
Copy link
Member

@nohwnd nohwnd commented Mar 19, 2026

Instead of hardcoding line number 22 for PassingTest, read the source file and find the [TestMethod] attribute line dynamically. This makes the test resilient to code moving around in the test asset.

Also removes the now-unnecessary debug/release branching since both branches had the same assertion.

Fixes #15448

Instead of hardcoding line number 22 for PassingTest, read the source
file and find the [TestMethod] attribute line dynamically. This makes
the test resilient to code moving around in the test asset file.

Also removes the now-unnecessary debug/release branching since both
branches had the same assertion.

Fixes microsoft#15448

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Copilot AI review requested due to automatic review settings March 19, 2026 17:30
Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Updates the integration test to derive the expected source-navigation line number from the actual test asset source, removing a brittle hardcoded line number and eliminating redundant build-configuration branching.

Changes:

  • Compute the expected line number by scanning UnitTest1.cs for PassingTest and its [TestMethod] attribute.
  • Remove the debug/release conditional since both branches asserted the same value.

Comment on lines +209 to +214
if (lines[i].Contains("public void PassingTest"))
{
// Source navigation points to the [TestMethod] attribute line, not the method declaration.
for (int j = i - 1; j >= 0; j--)
{
if (lines[j].Contains("[TestMethod]"))
Comment on lines +209 to +214
if (lines[i].Contains("public void PassingTest"))
{
// Source navigation points to the [TestMethod] attribute line, not the method declaration.
for (int j = i - 1; j >= 0; j--)
{
if (lines[j].Contains("[TestMethod]"))
Comment on lines +209 to +219
if (lines[i].Contains("public void PassingTest"))
{
// Source navigation points to the [TestMethod] attribute line, not the method declaration.
for (int j = i - 1; j >= 0; j--)
{
if (lines[j].Contains("[TestMethod]"))
{
expectedLineNumber = j + 1; // 1-based line number
break;
}
}
@nohwnd
Copy link
Member Author

nohwnd commented Mar 19, 2026

Closing - a better solution exists for this.

@nohwnd nohwnd closed this Mar 19, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

DiscoverTestsUsingSourceNavigation test fails when code moves around

2 participants