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; sourceforge. netprojectssimpletest
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", "[email protected]");
$ 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.