Repository navigation
Description
Describe the bug
JUnit XML reports do not include a file (or line) attribute on <testcase> elements. The serializer in src/JUnit.Xml.TestLogger/JunitXmlSerializer.cs sets only classname, name, and time on each testcase. VSTest exposes the source path and line number via TestCase.CodeFilePath / TestCase.LineNumber, but those values aren't propagated to the XML.
This breaks GitLab's Unit test reports UI, which reads the file attribute to populate its "Filename" column. With the attribute absent, the column renders as null and the column's copy-to-clipboard button copies the literal string "null".
The Jenkins JUnit XSD that this logger targets (jenkins-junit.xsd, referenced in #83) supports file/line on testcase, so adding them would be schema-compliant and additive.
- Test Runner: VSTest
- Test Framework: xUnit (the bug is in the JUnit serializer and is framework-agnostic; xUnit is what I observed it with)
- .NET project version, sdk version: net10.0, SDK 10.0.300
- Command line used:
dotnet test --logger:junit - OS: Linux
Expected behavior
Each <testcase> should include file="<source-path>" and line="<line-number>" populated from VSTest's TestCase.CodeFilePath / TestCase.LineNumber. With those attributes present, GitLab's Tests UI shows the source file in the Filename column (and the copy button copies the actual path).
Other details
- Minimal repro project: not attached — observable in any JUnit XML output, or by inspecting
JunitXmlSerializer.CreateTestCaseElementdirectly. - Logs from
dotnet test --diag:log.txtare attached.
Additional context
Current testcase serialization (src/JUnit.Xml.TestLogger/JunitXmlSerializer.cs, around lines 340–360):
testcaseElement.SetAttributeValue("classname", namespaceClass);
if (this.MethodFormatOption == MethodFormat.Full)
{
testcaseElement.SetAttributeValue("name", namespaceClass + "." + result.Method);
}
else if (this.MethodFormatOption == MethodFormat.Class)
{
testcaseElement.SetAttributeValue("name", result.Type + "." + result.Method);
}
else
{
testcaseElement.SetAttributeValue("name", result.Method);
}
testcaseElement.SetAttributeValue("time", ...);Adding file and line would be small and self-contained — read result.TestCase.CodeFilePath and result.TestCase.LineNumber and emit them as attributes when present.
Activity
fix: emit file and line attributes on JUnit testcase (#236)