Getting started with Unit Testing
Posted: Sun Jun 11, 2006 7:29 pm
I've decided I'm gonna test Swift inside out, upside down and back-to-front. I'm completely new to Unit testing so I figured I'd learn by doing it on something useful.
I've decided to go with SimpleTest and after reading the docs partway through I got impatient and though bah I'll just start and see what happens (I was finding the docs a little tedious to be honest).
I figured the best place to start would be at the heart of Swift and test the connection object (SMTP first).
I've only written one test so far and hopefully, with just a few adjustments it should apply to PHP5 too (loose the interface).
The test looks a bit long and repetitive though. Am I testing too many factors that are just, well, obvious?
For example, I've tested it with the constant, and then without it even though the constant is actually coded into the constructor as the default value. It's also pretty obvious that the handles will be false if nothin has been done in the object.
Maybe this is more sensible?
If I write all my tests like I wrote the first one then I'm going to have a good amount more code in the tests than I do in Swift itself 
Just looking for a "carry on..."
before I go too far doing the wrong thing.
Cheers,
d11
I've decided to go with SimpleTest and after reading the docs partway through I got impatient and though bah I'll just start and see what happens (I was finding the docs a little tedious to be honest).
I figured the best place to start would be at the heart of Swift and test the connection object (SMTP first).
I've only written one test so far and hopefully, with just a few adjustments it should apply to PHP5 too (loose the interface).
The test looks a bit long and repetitive though. Am I testing too many factors that are just, well, obvious?
Code: Select all
<?php
set_time_limit(0);
require_once('../docs/Swift_IConnection.php');
require_once('../Swift/Swift_SMTP_Connection.php');
require_once('../../simpletest/unit_tester.php');
require_once('../../simpletest/reporter.php');
class TestOfSMTPConnection extends UnitTestCase
{
public function TestCreatingUnencryptedConnectionOnDefaultPort()
{
$connection = new Swift_SMTP_Connection('smtp.gmail.com', SWIFT_DEFAULT_PORT);
$this->assertFalse($connection->isConnected());
$this->assertFalse($connection->readHook);
$this->assertFalse($connection->writeHook);
$this->assertTrue($connection->start());
$this->assertTrue($connection->isConnected());
$this->assertTrue($connection->readHook);
$this->assertTrue($connection->writeHook);
unset($connection);
$connection = new Swift_SMTP_Connection('smtp.gmail.com');
$this->assertFalse($connection->isConnected());
$this->assertFalse($connection->readHook);
$this->assertFalse($connection->writeHook);
$this->assertTrue($connection->start());
$this->assertTrue($connection->isConnected());
$this->assertTrue($connection->readHook);
$this->assertTrue($connection->writeHook);
unset($connection);
}
}
$test =& new TestOfSMTPConnection;
$test->run(new HtmlReporter());
?>Maybe this is more sensible?
Code: Select all
<?php
set_time_limit(0);
require_once('../docs/Swift_IConnection.php');
require_once('../Swift/Swift_SMTP_Connection.php');
require_once('../../simpletest/unit_tester.php');
require_once('../../simpletest/reporter.php');
class TestOfSMTPConnection extends UnitTestCase
{
public function TestCreatingUnencryptedConnectionOnDefaultPort()
{
$connection = new Swift_SMTP_Connection('smtp.gmail.com', SWIFT_DEFAULT_PORT);
$this->assertFalse($connection->isConnected());
$this->assertTrue($connection->start());
$this->assertTrue($connection->isConnected());
$this->assertTrue($connection->readHook);
$this->assertTrue($connection->writeHook);
unset($connection);
}
}
$test =& new TestOfSMTPConnection;
$test->run(new HtmlReporter());
?>Just looking for a "carry on..."
Cheers,
d11