MSDN Magazine Launch Issue - February 15, 2008 - (Page 32) Figure 3 to emit an extended results file. The overall idea is to build up the XML result file as one long string by capturing the results of each test case as each case is processed and then constructing the final string after the overall test result is known. I create an array of strings, one string for each test case, to hold the InnerTest values: var innerTestText = new Array(cases.length); extendedResults += “Passed ”; } else { extendedResults += “Failed ”; } I finish by adding the InnerTest data I saved earlier and writing the entire string as an XML file: extendedResults += “ ”; for (var j = 0; j < innerTestText.length; ++j) { extendedResults += “ ”; extendedResults += innerTestText[j]; extendedResults += “ ”; } extendedResults += “ ”; extendedResults += “ ”; var fso = new ActiveXObject(“Scripting.FileSystemObject”); var f = fso.CreateTextFile(“C:\\VSTTIntegration\\Scripts\\results.xml”); f.WriteLine(extendedResults); Inside the main processing loop I write out the TestName value and the start of the TestResult value: innerTestText[i] = “ ” + id + “ ”; innerTestText[i] += “ ”; // inner test result After I process an individual test case, I can supply a test result value and add the closing TestResult tag: if (actual == expected) { WScript.Echo(“Pass”); innerTestText[i] += “Passed”; } else { WScript.Echo(“FAIL”); innerTestText[i] += “Failed”; allPassed = false; } innerTestText[i] += “ ”; After the main processing loop has finished and all my InnerTest data has been constructed, I can create the first part of my extended results file: var extendedResults = “ ”; extendedResults += “ MyCOMLib Test Run ”; extendedResults += “ ”; // overall meta-result if (allPassed == true) { There are many other approaches you can take to emit XML results. My column “Five Ways to Emit Test Results as XML” in the June 2006 issue of MSDN® Magazine (msdn.microsoft.com/msdnmag/issues/06/06/TestRun) describes some of these techniques. At this point, I have a custom test automation script that writes detailed test results to a results.xml file that conforms to the SummaryResult.xsd schema. To use this automation from within VSTE for Testers, I create a new Generic Test around the automation using the technique I described earlier, but with one change. After Add | New Test and naming the test (say, Extended.GenricTest) in the definition pane, I check the Summary Results File checkbox and enter the location of the results file in the associated textbox Figure 7 Test Script that Emits an Extended Results File // testExtended.js function main() { WScript.Echo(“\nBegin test run\n”); var o = new ActiveXObject(“MyCOMLib.MyMethods”); var cases = new Array( “001:3*7*5:7”, “002:0*0*0:1”, “003:2*4*6:6” ); var allPassed = true; var innerTestText = new Array(cases.length); for (var i = 0; i < cases.length; ++i) { var tokens = cases[i].split(“:”); var id = tokens[0]; var inputs = tokens[1]; var expected = tokens[2]; var var var var temp arg1 arg2 arg3 = = = = inputs.split(“*”); temp[0]; temp[1]; temp[2]; else { WScript.Echo(“FAIL”); innerTestText[i] += “Failed”; allPassed = false; } innerTestText[i] += “ ”; } // main loop WScript.Echo(“==============”); var extendedResults = “ ”; extendedResults += “ MyCOMLib Test Run ”; extendedResults += “ ”; // overall meta-result if (allPassed == true) { extendedResults += “Passed ”; } else { extendedResults += “Failed ”; } extendedResults += “ ”; for (var j = 0; j extendedResults extendedResults extendedResults } < innerTestText.length; ++j) { += “ ”; += innerTestText[j]; += “ ”; WScript.Echo(“==============”); WScript.Echo(“Case ID = “ + id); WScript.Echo(“Inputs = “ + arg1 + “ “ + arg2 + “ “ + arg3); var actual = o.TriMax(arg1,arg2,arg3); WScript.Echo(“Expected = “ + expected); WScript.Echo(“Actual = “ + actual); innerTestText[i] = “ ” + id + “ ”; innerTestText[i] += “ ”; // inner test result if (actual == expected) { WScript.Echo(“Pass”); innerTestText[i] += “Passed”; } extendedResults += “ ”; extendedResults += “ ”; var fso = new ActiveXObject(“Scripting.FileSystemObject”); var f = fso.CreateTextFile(“C:\\VSTTIntegration\\Scripts\\results.xml”); f.WriteLine(extendedResults); f.Close(); } // main() main() 32 msdnmagazine Test Run http://msdn.microsoft.com/msdnmag/issues/06/06/TestRun http://msdn.microsoft.com/msdnmag/issues/06/06/TestRun
For optimal viewing of this digital publication, please enable JavaScript and then refresh the page. If you would like to try to load the digital publication without using Flash Player detection, please click here.