Differences

This shows you the differences between two versions of the page.

dev:web_application_testing [2005/10/04 05:07]
editor created
dev:web_application_testing [2009/07/06 20:36] (current)
Line 1: Line 1:
 +====== Web Application Testing Documentation ======
 +The web application testing for forms have been done using **simpletest** ([[http://www.lastcraft.com/simple_test.php]]) as the testing framework. Web form testing code convension to be used  is proposed in the following description.
 +
 +First to write the web test case the following php files have to be included in your document.
 +
 +<code php>
 +require_once($global['approot']."../3rd/simpletest/web_tester.php");
 +require_once($global['approot']."../3rd/simpletest/reporter.php");
 +require_once($global['approot']."functions.inc");
 +</code>
 +
 +The **web_tester.php** is the file which includes the functions related to web pages.
 +The **reporter.php** is for report generating purposes, and **functions.inc** would include several functions that can be used in random text stream generation to be used as inputs for the text fields of the forms.
 +
 +The path of the file to be tested could be included as given in the below coding.
 +
 +<code php>
 +global $test_file_name;
 +$test_file_name = $global['approot']."form.php";
 +</code>
 +
 +As the first step for web testing, a web test class should be created as follows.
 +
 +<code php>
 +class SimpleFormTest extends WebTestCase
 +{
 +}
 +</code>
 +Within this test case, the functions for testing should be written.
 +
 +<code php>
 +class SimpleFormTest extends WebTestCase
 +{
 +     function testName()
 + {
 + }
 +}
 +</code>
 +
 +The function name should be started with the word 'test'. **eg. testName()**
 +
 +Within the functions all the tests should be included.
 +
 +<code php>
 +class SimpleFormTest extends WebTestCase
 +{
 +     function testName()
 +    {
 + for($i=0;$i<=50;$i++){
 +     $test_name = str_makerand (0, 40, true, false, false); //generates a random text stream
 +               //refer functions.inc for more details
 +
 + $this->get($test_file_name);//gets the file given in the $test_file_name
 + $this->setField("name",$test_name);//sets the fileds of the page with the random stream
 + $this->setField("age",10);//sets the other fileds with correct inputs
 + $this->setField("gender","m");
 + $this->setField("country","LK");
 + $this->setField("ref","2005-24-25");
 + $this->setField("id",1);
 + $this->clickSubmit('Submit');//submit the page
 + $this->assertWantedText('added');//check for wanted text pattern from the target page and assert true if it is satisfied
 + }
 +    }
 +}
 +</code>
 +
 +Instead of the above assert statement, there are several asserts that can be used as you wish. Several of them are,
 +
 +  * assertTrue($x)Fail if $x is false
 +  * assertFalse($x)Fail if $x is true
 +  * assertNull($x)Fail if $x is set
 +  * assertNotNull($x)Fail if $x not set
 +  * assertIsA($x, $t)Fail if $x is not the class or type $t
 +  * assertNotA($x, $t)Fail if $x is of the class or type $t
 +  * assertEqual($x, $y)Fail if $x == $y is false
 +  * assertNotEqual($x, $y)Fail if $x == $y is true
 +  * assertIdentical($x, $y)Fail if $x == $y is false or a type mismatch
 +  * assertNotIdentical($x, $y)Fail if $x == $y is true and types match
 +  * assertReference($x, $y)Fail unless $x and $y are the same variable
 +  * assertCopy($x, $y)Fail if $x and $y are the same variable
 +  * assertWantedPattern($p, $x)Fail unless the regex $p matches $x
 +  * assertNoUnwantedPattern($p, $x)Fail if the regex $p matches $x
 +  * assertNoErrors()Fail if any PHP error occoured
 +  * assertError($x)Fail if no PHP error or incorrect message
 +  * assertErrorPattern($p)Fail unless the error matches the regex $p
 +
 +After writing all these test cases, the report can be displayed by including the following code segment at the end.
 +
 +<code php>
 +$test = &new SimpleFormTest();
 +$test->run(new HtmlReporter());
 +</code>
 +
 +The complete example code is given below for a test for a text filed.
 +<code php>
 +require_once($global['approot']."../3rd/simpletest/web_tester.php");
 +require_once($global['approot']."../3rd/simpletest/reporter.php");
 +require_once($global['approot']."functions.inc");
 +
 +global $test_file_name;
 +$test_file_name = $global['approot']."form.php";
 +
 +class SimpleFormTest extends WebTestCase
 +{
 +     function testName()
 +    {
 + for($i=0;$i<=50;$i++){
 +     $test_name = str_makerand (0, 40, true, false, false); //generates a random text stream
 +               //refer functions.inc for more details
 +
 + $this->get($test_file_name);//gets the file given in the $test_file_name
 + $this->setField("name",$test_name);//sets the fileds of the page with the random stream
 + $this->setField("age",10);//sets the other fileds with correct inputs
 + $this->setField("gender","m");
 + $this->setField("country","LK");
 + $this->setField("ref","2005-24-25");
 + $this->setField("id",1);
 + $this->clickSubmit('Submit');//submit the page
 + $this->assertWantedText('added');//check for wanted text pattern from the target page and assert true if it is satisfied
 + }
 +    }
 +}
 +$test = &new SimpleFormTest();
 +$test->run(new HtmlReporter());  
 +</code>
 +For more details on using simpletest and the function documentation refer [[http://www.lastcraft.com/web_tester_documentation.php]]
 +
 +
 + 

Navigation
  • Navigate