how to create a result as separate html file??

Discussion of testing theory and practice, including methodologies (such as TDD, BDD, DDD, Agile, XP) and software - anything to do with testing goes here. (Formerly "The Testing Side of Development")

Moderator: General Moderators

Post Reply
amira_fcis
Forum Newbie
Posts: 16
Joined: Sun Aug 16, 2009 7:59 am

how to create a result as separate html file??

Post 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
User avatar
mrvijayakumar
Forum Commoner
Posts: 58
Joined: Tue Aug 18, 2009 12:39 am
Location: Chennai city, India
Contact:

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

Post 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.
User avatar
Ollie Saunders
DevNet Master
Posts: 3179
Joined: Tue May 24, 2005 6:01 pm
Location: UK

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

Post 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.
amira_fcis
Forum Newbie
Posts: 16
Joined: Sun Aug 16, 2009 7:59 am

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

Post 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...?
User avatar
Ollie Saunders
DevNet Master
Posts: 3179
Joined: Tue May 24, 2005 6:01 pm
Location: UK

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

Post by Ollie Saunders »

Line 125 of simpletest/test_case.php on my version, which is a bit old now.
User avatar
Ollie Saunders
DevNet Master
Posts: 3179
Joined: Tue May 24, 2005 6:01 pm
Location: UK

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

Post 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 :-)
amira_fcis
Forum Newbie
Posts: 16
Joined: Sun Aug 16, 2009 7:59 am

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

Post 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
User avatar
Ollie Saunders
DevNet Master
Posts: 3179
Joined: Tue May 24, 2005 6:01 pm
Location: UK

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

Post by Ollie Saunders »

That's fine. What are you using SimpleTest for, out of interest?
amira_fcis
Forum Newbie
Posts: 16
Joined: Sun Aug 16, 2009 7:59 am

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

Post 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
User avatar
Ollie Saunders
DevNet Master
Posts: 3179
Joined: Tue May 24, 2005 6:01 pm
Location: UK

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

Post 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);
amira_fcis
Forum Newbie
Posts: 16
Joined: Sun Aug 16, 2009 7:59 am

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

Post 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);
 
    
?>
 
User avatar
Ollie Saunders
DevNet Master
Posts: 3179
Joined: Tue May 24, 2005 6:01 pm
Location: UK

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

Post by Ollie Saunders »

Try it!
amira_fcis
Forum Newbie
Posts: 16
Joined: Sun Aug 16, 2009 7:59 am

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

Post by amira_fcis »

yes ...i did ...but the file that i spacify to write output in still empty.... :roll:
User avatar
Ollie Saunders
DevNet Master
Posts: 3179
Joined: Tue May 24, 2005 6:01 pm
Location: UK

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

Post by Ollie Saunders »

If you comment out all the ob_* stuff do you get any output?
Otherwise, did you create the file manually first?
amira_fcis
Forum Newbie
Posts: 16
Joined: Sun Aug 16, 2009 7:59 am

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

Post by amira_fcis »

Ollie Saunders ur genius .... :wink:

it works perfect now ...thanks alot
Post Reply