SitePoint Sponsor

User Tag List

Results 1 to 2 of 2
  1. #1
    SitePoint Enthusiast
    Join Date
    Apr 2007
    Posts
    48
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Unhappy Need help with Simpletest

    I recently just started using simpletest and it is my first attempt at unit testing, so some of the things I test may seems odd, since I am just trying to learn the program and unit-testing.

    Prob 1: My first problem is when I include the dummytest.php file into the testsuite, for some reason the $scopetest variable being tested in dummytest is undefined, but if I run the test case separately it works fine. I can add "global" to the $scopetest variable in dummy.php and it will work, but it seems wrong...

    Concern: I'm also not sure if my test is setup right, since it invokes all the $test->run files...

    Prob 2: My second problem relates to the filetest.php file. When I run it separately it works fine, but when I run it using the testsuite it fails. It doesn't pass the parameter "test.txt" when the Testsuites run is invoked, but it works fileTest test case is run separately

    Code from fileTest.php test case
    Code:
    $test = new fileTest('test.txt');
    $test->run(new HtmlReporter());

    *** below relates to first problem ****
    This is my TestSuite file and it includes two test cases
    Code:
    <?php
    	
    	require_once('simpletest/unit_tester.php');
    	require_once('simpletest/reporter.php');
    	
    	class FileTestSuite extends TestSuite {
    	
    		function FileTestSuite() {
    			$this->TestSuite('All file tests');
    			$this->addTestFile('dummytest.php');
    			$this->addTestFile('filetest.php');
    		}	
    	
    	}
    	
       $test = &new FileTestSuite();
       $test->run(new HtmlReporter());
     ?>

    Dummy Test case file, which tests the dummy.php file
    Code:
    <?php
    
    include_once 'simpletest/unit_tester.php';
    include_once 'simpletest/reporter.php';
    
    include_once 'dummy.php';  
    
    class dummytest extends UnitTestCase
    {
    
        function dummytest()
        {
    	  $this->UnitTestCase('Sweet Function Test');      
    	}
    
        function setUp(){}
    
        function tearDown(){}
    
        function testSweet()
        {
    		$value = sweet(0);
    		$this->assertEqual(0, $value, "This is the wrong answer. Check your formula " . $value);        
    		
    		$value = sweet(25);
            $this->assertEqual(625, $value, "This is the wrong answer. Check your formula" . $value);
    		
    		$value = sweet(0.5);
    		$this->assertEqual(0.25, $value, "This is the wrong answer. Check your formula" . $value);
    	}
    
    	function testscope()
    	{
    		global $scopetest; 
    		$newValue = $scopetest; 
    		
    		$this->assertTrue($newValue, "Variable is not being set or called properly" . $newValue);
    	}
    
    }
    
    $test = new dummytest();
    $test->run(new HtmlReporter());
    ?>

    Dummy.php File
    Code:
    <?php
    
    function sweet($num) {
    
    	return $num * $num;
    }
    
    $scopetest = 55;
    
    ?>
    Last edited by chobo; Apr 28, 2007 at 16:42.

  2. #2
    SitePoint Enthusiast
    Join Date
    Apr 2007
    Posts
    48
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    I was under the impression that most people here actually used Simpletest. I guess not...


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •