PHP A brief test tool simpletest

Source: Internet
Author: User
PHP A simple test tool simpletest
PHPUnit is a good unit testing tool, and this article introduces a more lightweight unit testing tool, open source,
SimpleTest,

1 Downloads:
http://sourceforge.net/projects/simpletest/,
Unfortunately the document and project main station want that xxx, everybody understand

2 use
After the download, as long as the test file contains the following two files, you can use the
Require_once (' simpletest/autorun.php ');
Require_once (' simpletest/web_tester.php ');

?>

3 Test An interface, for example.
Require_once (' simpletest/autorun.php ');
Require_once (' simpletest/web_tester.php ');

Class Simpleformtests extends Webtestcase {

function Testdoescontactpageexist () {
$this->get (' http://www.example.com/contact.php ');
$this->assertresponse (200);
}

}

?>
You can also test the form's commit action.
function testisproperformsubmissionsuccessful () {

$this->get (' http://www.example.com/contact.php ');
$this->assertresponse (200);

$this->setfield ("name", "Jason");
$this->setfield ("email", "[email protected]");
$this->setfield ("message", "I look forward to hearing from you!");

$this->clicksubmit ("Contact us!");

$this->assertresponse (200);
$this->asserttext ("We'll be in touch within hours.");

}
You'll see what happens when you run it.



Another example of a unit test:
For example, there is a class log, which is a file created on disk

Require_once (' simpletest/unit_tester.php ');
Require_once (' simpletest/reporter.php ');
Require_once ('.. /classes/log.php ');

Class Testoflogging extends Unittestcase {

function Testcreatingnewfile () {
@unlink ('/temp/test.log ');
$log = new log ('/temp/test.log ');
$this->assertfalse (file_exists ('/temp/test.log '));
$log->message (' should write this to a file ');
$this->asserttrue (file_exists ('/temp/test.log '));
}
}

$test = &new testoflogging ();
$test->run (New Htmlreporter ());
?>

All of the test methods start with test by default, note that the $test->run (new Htmlreporter ()) is used last, and the output in HTML format is indicated.


  • Related Article

    Contact Us

    The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

    If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

    A Free Trial That Lets You Build Big!

    Start building with 50+ products and up to 12 months usage for Elastic Compute Service

    • Sales Support

      1 on 1 presale consultation

    • After-Sales Support

      24/7 Technical Support 6 Free Tickets per Quarter Faster Response

    • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.