Fitnesse is the newest automation tool I have introduced here, we also use
PowerShell to drive a lot of the builds, because there is some integration
between the two (think Smoke Test) I worked on getting the TestRunner working
with PowerShell. I couldn't get the .Net version to run properly, it kept dying
when it would render the page, but the Java runner worked great once I was able
to work through the java command line with the BuildMaster. If not for his help
I wouldn't have been able to finish.
This script launches the Java TestRunner, points it to the Fitnesse server,
and runs the three tests (one Test and two Suites) I currently have set up, then
scans through the XML results to display some results in the command line
window.
# Variables for the script
[string]$fitniumLocale = "C:
itnium"
[string]$fitnesseJar = "fitnesse.jar"
[string]$fitnesseClass = "fitnesse.runner.TestRunner"
[string]$serverName = "my_server"
[string]$portName = "8888"
# Use a Test Array to be able to bundle all the
tests
$testArray
= ( "Test1" , "Test2", "Test3"
)
function
main()
{
Write-Host "Running Fitnesse
Tester.`n"
cd $fitniumLocale
# Run
through each test in the bundle
$Java = "java.exe"
foreach ($test in $testArray)
{
#
Make a date string to get the right file
date/format
$dateStr = [string] (get-date)
$Month,$Day,$Year,$Hour,$Minute,$Second = $dateStr.split(" :/")
$testResults = "$test" + "$Month" + "$Day" + "$Year" + "$Hour" + "$Minute" + ".xml"
[string]$opts = "-xml
$testResults"
#
Start the test
Write-Host "`nRunning $test`n"
#
Get the output from Java so we can scrape it for the test passes and
fails
& $Java "-cp" "$fitnesseJar" "$fitnesseClass" "-xml" "$testResults" "$serverName" "$portName" "$test"
Write-Host "Completed $test`n"
Write-Host "Test Results"
#
Scan through the output file, we want that for
archiving
[System.Xml.XmlDocument] $xd = new-object
System.Xml.XmlDocument
$file =
resolve-path($testResults)
$xd.load($file)
$nodelist = $xd.selectnodes("/testResults/finalCounts") # XPath is case sensitive
foreach
($testCaseNode in $nodelist)
{
$right
= $testCaseNode.selectSingleNode("right").get_InnerXml()
$wrong
= $testCaseNode.selectSingleNode("wrong").get_InnerXml()
$ignores
= $testCaseNode.selectSingleNode("ignores").get_innerXml()
$exception = $testCaseNode.selectSingleNode("exceptions").get_InnerXml()
}
# Send a summary of the
results to the console
Write-Host "Passed:
$right"
-ForegroundColor Green
Write-Host "Failed:
$wrong"
-ForegroundColor Red
Write-Host "Ignored:
$ignores"
Write-Host "Exceptions: $exception" -ForegroundColor Yellow
}
}
main
It needs some cleaning up, but its a good first step that runs
well, I especially like the color coding for Pass, Fail and Exceptions so I can
visually be drawn to the values I want to see.
No comments:
Post a Comment