how to create a result as separate html file??
Moderator: General Moderators
-
amira_fcis
- Forum Newbie
- Posts: 16
- Joined: Sun Aug 16, 2009 7:59 am
how to create a result as separate html file??
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
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
- 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??
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.
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.
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);
?>- 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??
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:
It's not HTML of course but you could hack SimpleTest to produce HTML from the shell (or CLI in PHP terminology) fairly easily.
Code: Select all
./run_tests > test_results.txt-
amira_fcis
- Forum Newbie
- Posts: 16
- Joined: Sun Aug 16, 2009 7:59 am
Re: how to create a result as separate html file??
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...?
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...?
- 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??
Line 125 of simpletest/test_case.php on my version, which is a bit old now.
- 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??
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??
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
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
- 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??
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??
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
- 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??
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??
really iam soo greatful for u
do u mean that my test case will be some thing like that...
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);
?>
- Ollie Saunders
- DevNet Master
- Posts: 3179
- Joined: Tue May 24, 2005 6:01 pm
- Location: UK
-
amira_fcis
- Forum Newbie
- Posts: 16
- Joined: Sun Aug 16, 2009 7:59 am
Re: how to create a result as separate html file??
yes ...i did ...but the file that i spacify to write output in still empty.... 
- 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??
If you comment out all the ob_* stuff do you get any output?
Otherwise, did you create the file manually first?
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??
Ollie Saunders ur genius ....
it works perfect now ...thanks alot
it works perfect now ...thanks alot