Tagged: simpletest Toggle Comment Threads | Keyboard Shortcuts

  • danielsaidi 9:34 pm on September 15, 2011 Permalink | Reply
    Tags: pear, phpunit, simpletest,   

    Getting PEAR and PHPUnit to work with MAMP 

    When I recently decided to start re-developing a PHP project of mine from scratch, I decided to replace SimpleTest with PHPUnit and PHPCover.

    To get familiar with PEAR, I found this great tutorial:


    However, since I managed to screw up my PEAR configurations when playing around with it a month ago, the tutorial did not work.

    Turns out that PEAR was missing from where I wanted it to be installed, and that multiple PEAR installations were scattered all over the file system. The config file pointed to one of these locations, which made the installer believe that I had the latest release installed.

    Turns out that:

    Finally, I could follow the tutorial at the top of this post. Installing PHPUnit was a breeze after the invalid PEAR settings were fixed.

    You also need to grab PHPCover, which is described at https://github.com/sebastianbergmann/phpunit/

    Now, you have to set the include paths in /etc/php.ini. Mine looks like this:

    • include_path=”.:/php/includes:/usr/lib/php:/usr/lib/php/pear

    However, since I use MAMP, this is not the file that is to be. You need to modify the ini file in MAMP’s configuration area, and add the paths there as well.

    Now, PHPUnit will work, but I am yet to be convinced. SimpleTest seems easier to setup and flexible enough to cover all test cases I need, including mocking…plus that I can ship the testing framework with the development bundle.

    Any thoughts regarding this?

  • danielsaidi 6:45 pm on June 3, 2010 Permalink | Reply
    Tags: , , , simpletest,   

    Hide successful QUnit tests 

    I am now rolling with QUnit as TDD framework for my JavaScript development. It’s not as sophisticated as say NUnit for .NET or SimpleTest for PHP, but it’s reaaally easy to get started with.

    However, a strange way of designing the test result presentation is that QUnit lists all tests, not just the ones that fails. With just a few executing tests, the resulting page looks like this:

    QUnit - Full test result presentation

    By default, QUnit lists all executing tests in a test suite

    The test suite above only includes 14 tests – imagine having maybe a hundred or so! In my opinion, this way of presenting the test result hides the essence of testing – to discover tests that fail.

    I understand that one must be able to confirm that all tests are executed, but the number of executed tests are listed in the result footer. So, I would prefer to only list the tests that fail.

    If anyone knows a built-in way of achieving this, please let me know. I chose the following approach (applies to jQuery 1.4.2 – let me know if this is out-of date):

    1. Open the qunit.js file
    2. Find the block that begins with the line:
      var li = document.createElement("li");
    3. Wrap the entire block within:
      if (bad) { ... }

    This will make QUnit only append the list element if the test is “bad”, that is if it failed. The result will look like this:

    After fiddling with the code, QUnit only lists failing tests

    Maybe there is a built-in way of making QUnit behave like this. If you know how, please leave a comment.

  • danielsaidi 7:03 am on May 26, 2010 Permalink | Reply
    Tags: dirname, simpletest, __file__   

    Include and require files within included files in PHP 

    Today, I noticed this nice piece of code within the SimpleTest autorun.php file.

       require_once dirname(__FILE__) . '/unit_tester.php';

    Finding the folder of the current file, and not the executing file, is extremely useful when including/requiring files within files that are included by another page.

    When using dirname(__FILE__), the require operation works relative autorun.php, even if the file is included by another page. If this would not have been used, the page would have tried to look for the unit_tester.php file relative the including file, which would not have worked.

    I have previously solved this kind of folder issues with an “application root” path, but this is also a very nice approach.

    Thank you SimpleTest.

  • danielsaidi 11:43 pm on April 26, 2010 Permalink | Reply
    Tags: simpletest,   

    SimpleTest – Test Driven Development in PHP 

    In my daily work, working with .NET/C#, I love the way TDD and NUnit simplifies my work and allows me to focus on implementation instead of worrying about whether or not my new code will break anything already existing.

    When I develop PHP applications at home, however, I have not previously had any natural way of testing my code, since I have not had any good tool for testing my PHP code…and have not really put any effort into finding any such tool either.

    Today, however, this has changed. After starting developing Wigbi 1.0.0, I decided to browse the web and instantly found my dream tool – SimpleTest (can be downloaded at http://simpletest.org).

    It took me less than 5 minutes to download SimpleTest and use it to run my first test. It is simple (duh) and plain fantastic. If you are not into TDD, I strongly advice you to try it out…test is bliss.

Compose new post
Next post/Next comment
Previous post/Previous comment
Show/Hide comments
Go to top
Go to login
Show/Hide help
shift + esc