从< test-case>NUnit控制台运行程序设置TestResults.xml中的classname属性(解决方法JENKINS-53349)

3yhwsihp  于 2023-08-03  发布在  Jenkins
关注(0)|答案(1)|浏览(87)

我正在使用NUnit和Jenkins,遇到了Bug JENKINS-53349。它看起来不像这将很快得到修复,所以我想让这个工作。
这个bug很烦人,因为你看不到哪个测试失败了,测试结果输出也不稳定。假设您有一个带有一个参数的TestFixture,并且您使用10个不同的值运行它。夹具有5个测试。这将产生50个测试结果,其中仅随机显示5个。
有这个Bug JENKINS-53349,它表明问题如下:
TestResults.xml中,每个测试用例都有一个<test-case>标签。此标记具有classname属性。链接的Issues表明,如果此属性反映参数化的类名,则test-results-analyzer-plugin将正确呈现结果。

<!-- "Bad" version -->
<test-case id="0-1001" name="TestMethod(1)" fullname="ClassLibrary1.TestClass(&quot;a&quot;).TestMethod(1)" methodname="TestMethod" classname="ClassLibrary1.TestClass" runstate="Runnable" seed="491809005" result="Passed" start-time="2018-08-30 13:07:59Z" end-time="2018-08-30 13:07:59Z" duration="0.008806" asserts="0"/>
<!-- "Fixed" version -->
<test-case id="0-1001" name="TestMethod(1)" fullname="ClassLibrary1.TestClass(&quot;a&quot;).TestMethod(1)" methodname="TestMethod" classname="ClassLibrary1.TestClass(&quot;a&quot;)" runstate="Runnable" seed="491809005" result="Passed" start-time="2018-08-30 13:07:59Z" end-time="2018-08-30 13:07:59Z" duration="0.008806" asserts="0"/>

字符串
| 属性| attribute |
| --| ------------ |
| classname="ClassLibrary1.TestClass"个| classname="ClassLibrary1.TestClass" |
| classname="ClassLibrary1.TestClass(&quot;a&quot;)"个| classname="ClassLibrary1.TestClass(&quot;a&quot;)" |
我尝试在TestFixture中设置TestName,但不起作用。

[TestFixture("a", TestName = "ClassLibrary1.TestClass(a)")]
[TestFixture("b", TestName = "ClassLibrary1.TestClass(b)")]
// …

友情链接

  • NUnit的XML格式文档
c6ubokkw

c6ubokkw1#

我在powershell中编写了一个小脚本来“修复”XML。

param (
    [string]$xmlFilePath
)

# Check if the XML file exists
if (-not (Test-Path $xmlFilePath)) {
    Write-Host "Error: XML file not found at $xmlFilePath"
    Exit 1
}

# Load the XML file
[xml]$xmlDoc = Get-Content -Path $xmlFilePath

# Find all <test-case> elements in the XML
$testSuites = $xmlDoc.SelectNodes("//test-suite[@type='ParameterizedFixture']//test-case")

# Iterate over all elements and "fix" classname
# The real fix would be to fix jenkins
# - https://issues.jenkins.io/browse/JENKINS-53349
# - https://stackoverflow.com/questions/76045068
foreach ($testCase in $testSuites) {
    $i = $testCase.GetAttribute("fullname").LastIndexOf(".")
    $testCase.SetAttribute("classname", $testCase.GetAttribute("fullname").Substring(0, $i))
}

# $xmlDoc.Save([console]::out)

# Needs complete path
# https://stackoverflow.com/questions/4822575
$xmlDoc.Save((Resolve-Path $xmlFilePath))

Write-Host "XML file updated successfully"

字符串

相关问题