fix: emit file and line attributes on JUnit testcase#236
Merged
Conversation
JUnit XML <testcase> elements omitted file and line, so GitLab's Unit test reports UI rendered the Filename column as "null". VSTest exposes the source path and line number via TestCase.CodeFilePath / LineNumber and TestResultInfo already carried them through; the JUnit serializer just wasn't reading them. The Jenkins JUnit XSD supports both attributes, so this is an additive change. file is emitted when CodeFilePath is non-empty; line is emitted when LineNumber > 0. Resolves spekt#235
codito
approved these changes
Jun 20, 2026
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.
Context
The JUnit logger's
<testcase>elements omitfileandline. VSTest passesTestCase.CodeFilePath/LineNumberto the logger andTestResultInfocarries them, but the serializer doesn't emit them. The result is a blank Filename column in GitLab's Unit test reports UI — where "blank" renders as the literal stringnull.This change adds a block in
CreateTestCaseElementthat reads those properties and emits them as attributes when present. The Jenkins JUnit XSD permits both, so the change is additive.User-side requirement: populating the attributes requires
<CollectSourceInformation>true</CollectSourceInformation>in the consumer's runsettings — the VSTest gate that tells xUnit/MSTest adapters to read PDBs. Without it,CodeFilePatharrives empty and the attributes are omitted (same as today).Review guide
Core change
src/JUnit.Xml.TestLogger/JunitXmlSerializer.cs:362— emitfilewhenCodeFilePathis non-empty,linewhenLineNumber > 0Schema
test/assets/JUnit.xsd:85— add the two optional attributes so the acceptance-test XSD validator accepts the new outputTests
test/JUnit.Xml.TestLogger.UnitTests/JUnitXmlTestSerializerTests.cs:227— three cases: attributes present when source info is supplied,fileomitted when path is missing,lineomitted when0Sibling formats unchanged:
Xunit.Xml.TestLoggeralready emits<source-file>/<source-line>children on<test>(different format);NUnit.Xml.TestLogger's schema has no equivalent attributes.Resolves #235