While Lithium already comes with a text-based as well as web-based test interface, you may use or extend the Report class to create your own test reporter functionality. In addition, you can also create your own custom templates for displaying results in a different format, such as json. Example usage, for built-in HTML format/reporter: {{{ $report = new Report(array( 'title' => 'Test Report Title', 'group' => new Group(array('data' => array('\lithium\tests\cases\net\http\MediaTest'))), 'format' => 'html', 'reporter' => 'html' )); $report->run(); Get the test stats: $report->stats(); Get test results: $report->results }}} You may also choose to filter the results of the test runs to obtain additional information. For example, say you wish to calculate the cyclomatic complexity of the classes you are testing: {{{ $report = new Report(array( 'title' => 'Test Report Title', 'group' => new Group(array('data' => array('\lithium\tests\cases\net\http\MediaTest'))), 'filters' => array('Complexity') )); $report->run(); Get test results, including filter results: $report->results }}}
See also: lithium\test\Group
See also: lithium\test\filter
See also: lithium\test\templates
Inheritance: extends lithium\core\Object
Example #1
0
 public function testSingleTestWithMultipleFilters()
 {
     $all = array('Coverage', 'Complexity', 'Profiler', 'Affected');
     $permutations = $this->_powerPerms($all);
     foreach ($permutations as $filters) {
         $filters = array_flip($filters);
         $filters = array_map(function ($v) {
             return "";
         }, $filters);
         $report = new Report(array('title' => 'lithium\\tests\\mocks\\test\\MockFilterTest', 'group' => new Group(array('data' => array('lithium\\tests\\mocks\\test\\MockFilterClassTest')))));
         $report->filters($filters);
         $report->run();
         if (array_key_exists("Coverage", $filters)) {
             $expected = 66.67;
             $result = $report->results['filters'];
             $message = "Filter(s): '" . join(array_keys($filters), ", ") . "'";
             $message .= "returned no Coverage results.";
             $this->assertTrue(isset($result['lithium\\test\\filter\\Coverage']), $message);
             $percentage = $result['lithium\\test\\filter\\Coverage'];
             $percentage = $percentage['lithium\\tests\\mocks\\test\\MockFilterClass'];
             $percentage = $percentage['percentage'];
             $this->assertEqual($expected, $percentage);
         }
     }
 }
Example #2
0
 public function testSingleFilter()
 {
     $report = new Report(array('title' => '\\lithium\\tests\\mocks\\test\\MockFilterClassTest', 'group' => new Group(array('data' => array('\\lithium\\tests\\mocks\\test\\MockFilterClassTest'))), 'filters' => array("Complexity" => "")));
     $report->run();
     $class = 'lithium\\test\\filter\\Complexity';
     $result = $report->results['filters'][$class];
     $this->assertTrue(isset($report->results['filters'][$class]));
 }
 public function testStats()
 {
     $report = new Report(array('title' => '\\lithium\\tests\\mocks\\test\\MockUnitTest', 'group' => new Group(array('items' => array('\\lithium\\tests\\mocks\\test\\MockUnitTest')))));
     $report->run();
     $expected = "1 / 1 passes\n0 fails and 0 exceptions";
     $result = $report->stats();
     $this->assertEqual($expected, $result);
 }