iNET Interactive - Online Advertising Agency
          
   Home    Authors    About    Login    Contact Us
   Search:   
Advanced Search     
  Articles

  ASP (26)
  ASP.NET (19)
  C and C++ (4)
  CFML (2)
  CGI and Perl (16)
  Flash (2)
  Java (7)
  JavaScript (28)
  PHP (92)
  MySQL (13)
  MSSQL (3)
  HTML (34)
  SEO (9)
  Visual Basic (12)
  CSS (13)
  SSI (5)
  XML (12)
  C# (14)

  Developer News

May 12, 2008
Film Makers, Bands and Comedians Welcome on MySpace
About
 
May 12, 2008
Software Engineering for Ajax
WebReference.com
 
May 12, 2008
What is the Head Tag For?
About
 
May 11, 2008
Improving accessibility for motor impaired users
WebDevTips UK
 
May 11, 2008
10 ways to orientate users on your site
WebDevTips UK
 
May 11, 2008
Web Design Clinic - Rros restoration camp 2006
About
 
Courtesy of moreover.com
 
Want to receive new articles via e-mail? Click here!
/Home /PHP

UnitTesting in PHP using SimpleTest 

  Views:    32431
  Votes:    6
by Saleh Jamal 5/15/05 Rating: 

Synopsis:

Unit testing is writing more code which will test the main code wirtten by "throwing" sample data at it and examining what it gets back.
Pages: firstback1 2 3 4 6 7 forwardlast
The Article

Now, how many operations left to test? Two, right?
Here is the test for the method append():

    function testAppend()
    {
        $this->file->putContents("SimpleTest");
        $this->assertTrue($this->file->append("NeverMind"));
        $this->assertWantedPattern('~nevermind$~i', $this->file->getContents());
    }

Note that we didn't test the method putContents() again since it was tested before (tests are performed in the order they had been written in).
We use a new assertion method that is assertWantedPattern() which will try to match the regular expression pattern in the first argument against the second argument.
We want to make sure that the word "NeverMind" is found at the end of the file so the $ sign in regexp will help us.

And finally, our last test:

    function testDelete()
    {
        $this->assertTrue($this->file->delete());
        $this->assertFalse(file_exists($this->filename));
    }

There is no new assertion type used here and what I want to test is clear, so I need not say anything here, do I? It's pretty obvious :)

Pages: firstback1 2 3 4 6 7 forwardlast

Similar/related articles:


 
  Sponsors