Derive line numbers from source in DiscoverTestsUsingSourceNavigation#15524
Closed
nohwnd wants to merge 1 commit intomicrosoft:mainfrom
Closed
Derive line numbers from source in DiscoverTestsUsingSourceNavigation#15524nohwnd wants to merge 1 commit intomicrosoft:mainfrom
nohwnd wants to merge 1 commit intomicrosoft:mainfrom
Conversation
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>
Contributor
There was a problem hiding this comment.
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.csforPassingTestand 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; | ||
| } | ||
| } |
Member
Author
|
Closing - a better solution exists for this. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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