Dynamic Test results
Posted: Thu Nov 23, 2006 4:54 pm
I've written a test case which when run makes an unknown number of assertions as the test uses some arbitrary data in order to be a little fairer/well-covered:
Bceuase of the fact it's a bit random, the number of assertions made varies (massively) and thus, the results of the test case always display different numbers. If you keep refreshing the page you just keep seeing a green bar with changing numbers. Would this put people off trusting the test?
Hmm... come to think of it, as simple pattern would probably suffice, although the failure details wouldn't be as clear.
Code: Select all
public function testLinesInBodyCannotExceedSpecifiedLength()
{
$mime = new MimeExtension();
$mime->setLineWrap(76);
$str = "";
for ($i = 0; $i < 2000; $i++)
{
$str .= chr(rand(32, 126)); //Ascii chars
}
$mime->setData($str);
$structure = $mime->build();
$body = substr($structure, strpos($structure, "\r\n\r\n")+4);
$lines = explode("\r\n", $body);
foreach ($lines as $line)
{
$line .= "\r\n"; //lost in explode()
$this->assertWithinMargin(0, strlen($line), 76);
}
$mime = new MimeExtension();
$mime->setLineWrap(1000);
$mime->setData($str);
$structure = $mime->build();
$body = substr($structure, strpos($structure, "\r\n\r\n")+4);
$lines = explode("\r\n", $body);
foreach ($lines as $line)
{
$line .= "\r\n"; //lost in explode()
$this->assertWithinMargin(0, strlen($line), 1000);
}
$length = rand(10, 700);
$mime = new MimeExtension();
$mime->setLineWrap($length);
$mime->setData($str);
$structure = $mime->build();
$body = substr($structure, strpos($structure, "\r\n\r\n")+4);
$lines = explode("\r\n", $body);
foreach ($lines as $line)
{
$line .= "\r\n"; //lost in explode()
$this->assertWithinMargin(0, strlen($line), $length);
}
}Hmm... come to think of it, as simple pattern would probably suffice, although the failure details wouldn't be as clear.