Php simpletest, a simple test tool

Source: Internet
Author: User
A simple php testing tool simpletestphpunit is a good unit testing tool. This article introduces a more lightweight unit testing tool, open source, simpletest, 1 download: & nbsp; http://sourceforge.net/projects/simpletes php a simple test tool simpletest
Phpunit is a good unit test tool. This article introduces a more lightweight unit test tool, open-source,
Simpletest,

1 download:
Http://sourceforge.net/projects/simpletest,
Unfortunately, the XXX document and project main site is required.

2. use
After the download, you can use the following two files in the Test File:
Require_once ('simpletest/autorun. php ');
Require_once ('simpletest/web_tester.php ');

?>

3. test an interface.
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 submission action.
Function testIsProperFormSubmissionSuccessful (){

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

$ This-> setField ("name", "Jason ");
$ This-> setField ("email", "wj@example.com ");
$ This-> setField ("message", "I look forward to hearing from you! ");

$ This-> clickSubmit ("Contact us! ");

$ This-> assertResponse (200 );
$ This-> assertText ("We will be in touch within 24 hours .");

}
After running, you will see the pass



Another example of unit test is as follows:
For example, there is a class LOG that creates a file on the 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 ('Could 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 $ test-> run (new HtmlReporter (); is used to output data in HTML format.


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.