我们目前正在使用FitNesse进行自动化测试。我正在使用VSTS将其集成到我们的构建中,并需要发布测试结果。将FitNesse XML测试结果转换为JUnit格式
FitNesse测试结果保存在xml中,需要转换为VSTS可以理解的JUnit格式。理想情况下,我想使用一个PowerShell脚本,这将使转换为JUnit成为可能。
有没有人以前做过或有一个示例脚本转换为JUnit格式。
非常感谢
我们目前正在使用FitNesse进行自动化测试。我正在使用VSTS将其集成到我们的构建中,并需要发布测试结果。将FitNesse XML测试结果转换为JUnit格式
FitNesse测试结果保存在xml中,需要转换为VSTS可以理解的JUnit格式。理想情况下,我想使用一个PowerShell脚本,这将使转换为JUnit成为可能。
有没有人以前做过或有一个示例脚本转换为JUnit格式。
非常感谢
也许误解的东西在这里,但: http://www.fitnesse.org/FitNesse.UserGuide.AdministeringFitNesse.RestfulServices
急救员
format=junit Produces simple jUnit XML format
感谢您的帮助球员。我们最终创建了自己的PowerShell脚本,以获取类名,套件和失败类型。如果有人愿意使用,请在下面发布。
param([string]$outpath, [string]$testserver, [string]$suitename)
$uri = "http://" + $testserver + "/" + $suitename + "?suite&format=xml"
$resultString = Invoke-WebRequest -Uri $uri
$xml = New-Object xml
$xml.LoadXml($resultString)
$tests = @{}
foreach($result in $xml.testResults.result)
{
$pageName = $result.pageHistoryLink.Substring(0, $result.pageHistoryLink.IndexOf("?"))
foreach ($ir in $result.instructions.instructionResult)
{
$i =$ir.instruction.Replace("=",":")
$argsloc = $i.LastIndexOf(', args:')
if ($argsloc -gt 0)
{
$i=$i.Substring(0, $argsloc) + "}"
}
$instr =convertFrom-Json $i
if ($instr.instruction -eq "import")
{
continue
}
if ($instr.instruction -eq "make")
{
$t=New-Object psobject
$classname = $pagename + "." + $instr.className
Add-Member -InputObject $t -MemberType NoteProperty -Name className -Value $classname
Add-Member -InputObject $t -MemberType NoteProperty -Name scenarios -Value @{}
$tests.add($pagename + "." + $instr.instanceName, $t)
}
if ($instr.instruction -eq "call")
{
$t=$tests[$pagename + "." + $instr.instanceName]
if (-not($t.scenarios.ContainsKey($ir.expectation.row)))
{
$s=New-Object psobject
Add-Member -InputObject $s -MemberType NoteProperty -Name pass -Value $true
Add-Member -InputObject $s -MemberType NoteProperty -Name failures -Value @()
$t.scenarios.add($ir.expectation.row, $s)
}
if ($ir.expectation.status -eq $null)
{
continue
}
if ($ir.expectation.status -eq "pass")
{
continue
}
$LASTEXITCODE = 1
$scenario = $t.scenarios[$ir.expectation.row]
$scenario.pass =$false
$scenario.failures += ("Method Name: "+ $instr.methodName + " - Expected: " + $ir.expectation.expected + ", Actual: " + $ir.expectation.actual)
}
}
}
$doc = New-Object System.Xml.XmlDocument
$suites = $doc.CreateElement("testsuites")
$res=$doc.AppendChild($suites)
$ts = $doc.CreateElement("testsuite")
$res=$suites.AppendChild($ts)
foreach ($testkey in $tests.Keys)
{
$test = $tests[$testkey]
$test
foreach ($scenariokey in $test.scenarios.Keys)
{
$scenario =$test.scenarios[$scenariokey]
$tc = $doc.CreateElement("testcase")
$attr=$doc.CreateAttribute("classname")
$res=$attr.Value= $test.className
$res=$tc.Attributes.Append($attr)
$attr=$doc.CreateAttribute("name")
$res=$attr.Value= $test.className
$res=$tc.Attributes.Append($attr)
if (-not($scenario.pass))
{
$errString = [string]::Join(": ", $scenario.failures)
$scenario.failures.GetType()
$fail = $doc.CreateElement("failure")
$attr=$doc.CreateAttribute("message")
$res=$attr.Value= $errString
$res=$fail.Attributes.Append($attr)
#$fail.innertext = $errString
$res=$tc.AppendChild($fail)
}
$res=$ts.AppendChild($tc)
}
}
$doc.Save($outpath)
你尝试过什么? XSLT是一个选项吗? – MartinByers
我有一个XSLT文件,我很遗憾无法共享......棘手的部分是在'FitNesseRoot/files/testResults'内的测试套件中打开每个单独测试的结果(使用XSLT'document'函数) ,然后提取您想要查看的详细程度。 – legoscia
感谢@legoscia,这听起来像是一个不错的选择。您是否使用XSLT函数转换为JUnit?我的目标是希望将它变成PowerShell脚本。这是你做的事吗?或者有一个例子可以帮助我开始吗? – Sej