Skip to content

Output Formats

nzakas edited this page Nov 23, 2011 · 1 revision

YUI Test allows you to retrieve test information in a few different formats. This can be used either through the YUITest.TestRunner.getResults() method or with the YUITest.TestReporter object. By default, YUITest.TestRunner.getResults() returns an object representing the results of the tests that were just run (the method returns null if called while tests are still running). You can optionally specify a format in which the results should be returned. There are four possible formats:

  • YUITest.TestFormat.XML - YUI Test XML (default for TestReporter)
  • YUITest.TestFormat.JSON - JSON
  • YUITest.TestFormat.JUnitXML - JUnit XML
  • YUITest.TestFormat.TAP - TAP

You can pass any of these into YUITest.TestRunner.getResults() to get a string with the test result information properly formatted. For example:

//get object of results
var resultsObject = YUITest.TestRunner.getResult();

//get XML results
var resultsXML = YUITest.TestRunner.getResult(YUITest.TestFormat.XML);         

The XML format outputs results in the following format:


<?xml version="1.0" encoding="UTF-8" ?>
&lt;report name="YUI Test Results" passed="5" failed="3" ignored="1" total="5"&gt;
  &lt;testsuite name="yuisuite" passed="5" failed="0" ignored="0" total="5"&gt;
    &lt;testcase name="Y.Anim" passed="5" failed="0" ignored="0" total="5"&gt;
      &lt;test name="test_getEl" result="pass" message="Test passed" /&gt; 
      &lt;test name="test_isAnimated" result="pass" message="Test passed" /&gt; 
      &lt;test name="test_stop" result="pass" message="Test passed" /&gt; 
      &lt;test name="test_onStart" result="pass" message="Test passed" /&gt; 
      &lt;test name="test_endValue" result="pass" message="Test passed" /&gt; 
    &lt;/testcase&gt;
  &lt;/testsuite&gt;
&lt;/report&gt;

The JSON format requires that a JSON serializer be available. The native JSON utility is used when available. Otherwise, you'll need to point YUITest.Util.JSON at an implementation containing the stringify() method. If you're using YUI 2.x, you can point to YAHOO.lang.JSON; if you're using YUI 3.x, you can point to Y.JSON; otherwise, you can use the json2.js library. Results are output in a format that follows the object/array hierarchy of the results object, such as:

{
    "passed": 5,
    "failed": 0,
    "ignored": 0,
    "total": 0,
    "type": "report",
    "name": "YUI Test Results",
    
    "yuisuite":{
        "passed": 5,
        "failed": 0,
        "ignored": 0,
        "total": 0,
        "type": "testsuite",
        "name": "yuisuite",
        
        "Y.Anim":{
            "passed": 5,
            "failed": 0,
            "ignored": 0,
            "total": 0,
            "type":"testcase",
            "name":"Y.Anim",
            
            "test_getEl":{
                "result":"pass",
                "message":"Test passed.",
                "type":"test",
                "name":"test_getEl"            
            },
            "test_isAnimated":{
                "result":"pass",
                "message":"Test passed.",
                "type":"test",
                "name":"test_isAnimated"            
            },
            "test_stop":{
                "result":"pass",
                "message":"Test passed.",
                "type":"test",
                "name":"test_stop"            
            },
            "test_onStart":{
                "result":"pass",
                "message":"Test passed.",
                "type":"test",
                "name":"test_onStart"            
            },
            "test_endValue":{
                "result":"pass",
                "message":"Test passed.",
                "type":"test",
                "name":"test_endValue"            
            }        
        }
    }
}

The JUnit XML format outputs results in the following format:


&lt;?xml version="1.0" encoding="UTF-8" ?&gt;
&lt;testsuites&gt;
    &lt;testsuite name="Y.Anim" failures="0" total="5" time="0.0060"&gt;
        &lt;testcase name="test_getEl" time="0.0"&gt;&lt;/testcase&gt;
        &lt;testcase name="test_isAnimated" time="0.0010"&gt;&lt;/testcase&gt;
        &lt;testcase name="test_stop" time="0.0010"&gt;&lt;/testcase&gt;
        &lt;testcase name="test_onStart" time="0.0010"&gt;&lt;/testcase&gt;
        &lt;testcase name="test_endValue" time="0.0010"&gt;&lt;/testcase&gt;
    &lt;/testsuite&gt;  
&lt;/testsuites&gt;

Note that there isn't a direct mapping between YUI Test test suites and JUnit test suites, so some of the hierarchical information is lost.

The TAP format outputs results in the following format:

1..5
#Begin report YUI Test Results (0 failed of 5)
#Begin testcase Y.Anim (0 failed of 5)
ok 1 - testGetServiceFromUntrustedModule
ok 2 - testGetServiceFromTrustedModule
ok 3 - testGetServiceFromService
ok 4 - testGetServiceMultipleTimesFromService
ok 5 - testGetServiceMultipleTimesFromUntrustedModule
#End testcase Y.Anim
#End report YUI Test Results

The XML, JSON, and JUnit XML formats produce a string with no extra white space (white space and indentation shown here is for readability purposes only).

Clone this wiki locally