TestFormat.js revision 02adbfa608c27f6582f8c989f81cbf054fba8a72
/**
* An object object containing test result formatting methods.
* @namespace YUITest
* @class TestFormat
* @static
*/
YUITest.TestFormat = function(){
/* (intentionally not documented)
* Basic XML escaping method. Replaces quotes, less-than, greater-than,
* apostrophe, and ampersand characters with their corresponding entities.
* @param {String} text The text to encode.
* @return {String} The XML-escaped text.
*/
switch(value){
case "\"": return """;
case "'": return "'";
case "&": return "&";
}
});
}
return {
/**
* Returns test results formatted as a JSON string. Requires JSON utility.
* @param {Object} result The results object created by TestRunner.
* @return {String} A JSON-formatted string of results.
* @method JSON
* @static
*/
},
/**
* Returns test results formatted as an XML string.
* @param {Object} result The results object created by TestRunner.
* @return {String} An XML-formatted string of results.
* @method XML
* @static
*/
function serializeToXML(results){
}
} else {
xml += " passed=\"" + results.passed + "\" failed=\"" + results.failed + "\" ignored=\"" + results.ignored + "\" total=\"" + results.total + "\">";
}
}
}
}
return xml;
}
},
/**
* Returns test results formatted in JUnit XML format.
* @param {Object} result The results object created by TestRunner.
* @return {String} An XML-formatted string of results.
* @method JUnitXML
* @static
*/
function serializeToJUnitXML(results){
var xml = "";
//equivalent to testcase in JUnit
case "test":
xml = "<testcase name=\"" + xmlEscape(results.name) + "\" time=\"" + (results.duration/1000) + "\">";
xml += "<failure message=\"" + xmlEscape(results.message) + "\"><![CDATA[" + results.message + "]]></failure>";
}
xml+= "</testcase>";
}
break;
//equivalent to testsuite in JUnit
case "testcase":
xml = "<testsuite name=\"" + xmlEscape(results.name) + "\" tests=\"" + results.total + "\" failures=\"" + results.failed + "\" time=\"" + (results.duration/1000) + "\">";
}
}
}
xml += "</testsuite>";
break;
//no JUnit equivalent, don't output anything
case "testsuite":
}
}
}
break;
//top-level, equivalent to testsuites in JUnit
case "report":
xml = "<testsuites>";
}
}
}
xml += "</testsuites>";
//no default
}
return xml;
}
},
/**
* Returns test results formatted in TAP format.
* For more information, see <a href="http://testanything.org/">Test Anything Protocol</a>.
* @param {Object} result The results object created by TestRunner.
* @return {String} A TAP-formatted string of results.
* @method TAP
* @static
*/
var currentTestNum = 1;
function serializeToTAP(results){
var text = "";
case "test":
}
text += "\n";
} else {
}
break;
case "testcase":
text = "#Begin testcase " + results.name + "(" + results.failed + " failed of " + results.total + ")\n";
}
}
}
break;
case "testsuite":
text = "#Begin testsuite " + results.name + "(" + results.failed + " failed of " + results.total + ")\n";
}
}
}
break;
case "report":
}
}
}
//no default
}
return text;
}
}
};
}();