Dashboard > ringside > ... > Documentation > Testing Infrastructure
Testing Infrastructure Log In | Sign Up   View a printable version of the current page.

Testing Infrastructure

Layout

  • There are two main testing frameworks that are used in the codebase:
  • Every class must have an associated unit test class with appropriate tests to cover it as close to 100% as possible. If there are no tests, please write some. Due to the nature of PHP, it is imperative that we get as close to 100% code coverage as we can.
  • Tests for each subsystem (api, social, etc) are located under its individual test directory separated in subdirectories called unit, functional, and system:
    • Unit test - Completely independent and standalone; intended to run inside an IDE or from build.xml immediately after an SVN download with zero (or near-zero) configuration. No external dependencies, including (but not limited to) databases, HTTP servers, file system configuration, etc. should be needed by the tests.
    • Functional test - Dependent on some external resource (very preferably no more than one), but not dependent on a particular distribution or arrangement of those resources. May need to start up/shut down databases, HTTP servers, etc. in order to fully test the functionality of a given component. 90+% of the tests we have fall into this category.
    • System test - A test that is intended to be run in the final distribution environment. These tests may impose certain deployment constraints (e.g. a Ringside server configured against a database with Facebook running in the cloud).
  • DB setup files are typically named <testsuite>-setup.sql or <testsuite>-teardown.sql
  • Tests are run via Phing
    • phing api-tests
    • Test reports are generated into reports
  • Here's an example of a PHPUnit unit test:
    <?php
    require_once( 'PHPUnit/Framework.php' );
    require_once( '<what-ever-you-need>' );
    
    class <YourClass>TestCase extends PHPUnit_Framework_TestCase
    {
        public function setUp()
        {
            // perform some test setup
        }
     
        public function tearDown()
        {
            // perform some test cleanup
        }
     
        /**
         * If you want to provide different data to multiple calls to test functions,
         * return an array of data; each data element results in a call to
         * the test function.
         */
        public static function providerTestExecute()
        {
            return array(
              array( 0 ),
              array( 1 ),
              array( 2 )
            );
        }
    
        /**
         * Test some functionality.
         *
         * This line makes PHPunit call providerTestExecute with however many
         * datasets (arrays are there).
         * @dataProvider providerTestExecute
         */
        public function testExecute( $code=0 )
        {  
             $this->assertTrue(  $code == 2 );
        }
    }
    ?>

Adding New Tests

TODO: talk about how to add new tests to the different modules

Running Tests

TODO: talk about how to run the tests from the different modules

How to Run the API Functional Tests

  • Make sure you have a DB setup for use with the tests
  • Specify your MySQL connection info your LocalSettings.php file in the root of your Ringside source
  • Run the client tests from the api/test/functional directory:
    • phing all-tests

How to Run the API System Tests (the client tests)

  • Make sure the API functional tests run and pass (see previous section)
  • If your SVN working space is not already deployed as your Ringside instance, you must deploy Ringside in an Apache Web Server somewhere by following these steps:
    • Set the deploy parameters in build/build.local.properties:

      deploy.includes=<includes directory>
      deploy.public=<htdocs directory, could be same as includes>
      deploy.config=<includes directory>
      deploy.clients=<includes directory>
      #comment this line out if you want your LocalSettings.php to be re-created each build
      no.config.rewrite=true

    • Deploy the distribution to your deployed instance:
      • cd build
      • phing -f build-deploy.xml
  • Run the PHP client tests from the api/test/system directory:
    • phing client-tests-php
  • Optionally run the PHP Java client tests from the api/test/system directory (note: you must have java installed and in your PATH environment):
    • phing client-tests-java
Added by John Mazzitelli , last edited by Mike Schachter on Jun 11, 2008  (view change)
Labels: 
(None)