Page 1 of 1

how to create a result as separate html file??

Posted: Mon Aug 17, 2009 7:17 am
by amira_fcis
hi guys,..
iam very new with simpletest frame work and i tried some small testing app,...but my question is: could i create a separate HTML file which view the results of testing.(i.e i want a file say testResult.html which contains the result of test).


thanks for advance

Re: how to create a result as separate html file??

Posted: Wed Aug 19, 2009 8:44 am
by mrvijayakumar
Hello ,
I hope this code will satisfy your needs. Try this code, if it's OK means u can use it. Don't forget to see note below the code.

Code: Select all

<?php
$testresult = "hello world!";
 
$testresult = addslashes($testresult);
 
$fileoutput = "<!DOCTYPE html PUBLIC '-//W3C//DTD XHTML 1.0 Transitional//EN' 'http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd'>
<html xmlns='http://www.w3.org/1999/xhtml'>
<head>
<meta http-equiv='Content-Type' content='text/html; charset=iso-8859-1' />
<title>Testing Result</title>
</head>
 
<body>
$testresult
</body>
</html>";
 
$filename = "test_".rand(1,10000).".html";
 
$fp = fopen($filename, 'w');
fwrite($fp, $fileoutput);
fclose($fp);
 
 
?>
Note: Input your output (Result to print on html file) on ' $testresult ' and file name will auto generated with starting prefix 'test_' followed with random number.

Re: how to create a result as separate html file??

Posted: Wed Aug 19, 2009 10:07 pm
by Ollie Saunders
The result of an individual assertion or a whole suite of tests? Because if you're after the latter and you're currently running the tests from the shell you could just redirect the output:

Code: Select all

./run_tests > test_results.txt
It's not HTML of course but you could hack SimpleTest to produce HTML from the shell (or CLI in PHP terminology) fairly easily.

Re: how to create a result as separate html file??

Posted: Thu Aug 20, 2009 4:46 am
by amira_fcis
sorry for distribution,..

but i have a simple question...where is the simpletest APIs and functions as $test->run(new HtmlReporter()); or something like that...that i have to use to produce the result...?

Re: how to create a result as separate html file??

Posted: Thu Aug 20, 2009 7:45 am
by Ollie Saunders
Line 125 of simpletest/test_case.php on my version, which is a bit old now.

Re: how to create a result as separate html file??

Posted: Thu Aug 20, 2009 7:47 am
by Ollie Saunders
If you are hacking SimpleTest best thing you could do, design wise, would be to write a SaveAsFileReporter. You can see the existing reporter implementations in simpletest/reporter.php. Without looking too closely you'll probably want to start by subclassing SimpleReporter. Ah, it's all so "Simple" in SimpleTest :-)

Re: how to create a result as separate html file??

Posted: Thu Aug 20, 2009 8:22 am
by amira_fcis
thanks Ollie Saunders for ur concern with my post

may be it is simple from ur point of view ..but i still newbie to this concept of testing at all ,so if u have any type of helpful links or guides i'll be more than thankful...

thanks

Re: how to create a result as separate html file??

Posted: Thu Aug 20, 2009 8:49 am
by Ollie Saunders
That's fine. What are you using SimpleTest for, out of interest?

Re: how to create a result as separate html file??

Posted: Thu Aug 20, 2009 8:54 am
by amira_fcis
i just begin with the tutorial on simpletest main site and i made it succesfully ,but all what i need now is to make output of the testing to be written in text file instead of running as TextReporter() or HtmlReporter()...that is all

Re: how to create a result as separate html file??

Posted: Thu Aug 20, 2009 8:57 am
by Ollie Saunders
Thinking about it, this is probably your simplest way:

Code: Select all

ob_start();
$test->run(new HtmlReporter);
$testOutput = ob_get_contents();
ob_end_clean();
file_put_contents($fileName, $testOutput);

Re: how to create a result as separate html file??

Posted: Thu Aug 20, 2009 9:11 am
by amira_fcis
really iam soo greatful for u :oops:

do u mean that my test case will be some thing like that...

Code: Select all

 
<?
    require_once('plugins\unit_tester.php');
    require_once('plugins\reporter.php');
    
 
 
    $test = &new GroupTest('All tests');
    $test->addTestFile('string_tests.php');
    $test->addTestFile('array_tests.php');
 
    
    ob_start();
        $test->run(new HtmlReporter);
        $testOutput = ob_get_contents();
        ob_end_clean();
        $f = "logs/testlog.txt";
        file_put_contents($f, $testOutput);
 
    
?>
 

Re: how to create a result as separate html file??

Posted: Thu Aug 20, 2009 9:14 am
by Ollie Saunders
Try it!

Re: how to create a result as separate html file??

Posted: Thu Aug 20, 2009 9:15 am
by amira_fcis
yes ...i did ...but the file that i spacify to write output in still empty.... :roll:

Re: how to create a result as separate html file??

Posted: Thu Aug 20, 2009 9:22 am
by Ollie Saunders
If you comment out all the ob_* stuff do you get any output?
Otherwise, did you create the file manually first?

Re: how to create a result as separate html file??

Posted: Thu Aug 20, 2009 9:30 am
by amira_fcis
Ollie Saunders ur genius .... :wink:

it works perfect now ...thanks alot