Update:Remora Testing: Difference between revisions

From MozillaWiki
Jump to navigation Jump to search
No edit summary
No edit summary
Line 1: Line 1:
===Where are they?===
/app/tests/
===Model Tests===
===Model Tests===
Example forthcoming.
Example forthcoming.
Line 34: Line 37:
?>
?>
</pre>
</pre>
===Other tests===
In general we'd want to use the same framework for external tests -- stuff like:
* PFS
* Update
* Maintenance and other /bin tests
If that is not possible, they will be in the same directory with the thing they are testing (database migration tests, for example would live alongside the script in the same directory).
Tests for external scripts are in /app/tests/services/.


===Why do we write tests?===
===Why do we write tests?===

Revision as of 17:44, 5 September 2006

Where are they?

/app/tests/

Model Tests

Example forthcoming.

Controller Tests

Controller tests must be located in the models directory. Example will be posted here eventually.

Component Tests

Components can be tested as displayed in the following example. Note that these must be saved in the models directory.

File path: /var/www/html/fligtar/app/tests/app/cases/models/rdf.test.php

Web path: http://142.204.140.147:8080/fligtar/tests/cases?case=models%2Frdf.test.php&app=true

<?php
class RdfTest extends UnitTestCase {
        //Setup the RDF Component
        function setUp() {
                loadComponent('Rdf');
                $this->Rdf =& new RdfComponent();
        }

        //Make sure there are no PHP errors
        function testNoErrors() {
                $this->assertNoErrors();
        }

        //Make sure the XML returns an array of parsed data
        function testIsArray() {
                $results = $this->Rdf->parseInstallManifest($this->manifestData);
                $this->assertIsA($results, 'array');
                $this->returnedArray = $results;
        }
}
?>

Other tests

In general we'd want to use the same framework for external tests -- stuff like:

  • PFS
  • Update
  • Maintenance and other /bin tests

If that is not possible, they will be in the same directory with the thing they are testing (database migration tests, for example would live alongside the script in the same directory).

Tests for external scripts are in /app/tests/services/.

Why do we write tests?

We write tests because they let us go faster, even early in development, by revealing downstream effects of changes earlier.

Some good reads:

We write tests because they improve the quality of our code, by pushing us to factor better, reduce dependencies on other state, and keep control flow simpler.

We write tests because they document code better than comments, and because seeing a green bar makes us feel tingly inside, like when Sally held our hand on the school bus in grade 4.

We write tests the best we can, knowing that we won't be perfect, and adding more tests as we encounter them. We know that writing tests as we write code will encourage us to make smaller changes and focus on the specific problem at hand. We are learning to trust and fear the feeling in our stomach that says that a change is risky because there isn't a good test for some of the things it effects.

We think morgamic is pretty cute. But we don't have a test for it, so we're not really confident.