Automatic testing in Streberπ
We use simpletest's web_tester module for testing. This emulates a browser and simulates real clickflows and checks the results. You can login, change a users password, logout and test if the new password is working. So this is more integration testing than unit testing. This is nice for:
- Tests are very easy to write.
- Since pixtur added sql fixtures you can test complex setup involving several users and projects.
- You can easily valid html structure, user data escaping and much more.
It fails on:
- Javascript
- Internal structures
Running the testsπ
The tests are executed when requesting `
http://localhost/streber/tests/testsuite_pages.php`. There are about 600 tests which take about 30 seconds on pixtur's notebook. Right now the tests uses database snapshots as sql-dumps as fixtures. These dumps are located at
tests/fixtures/*.sql. The testing sql tables get the prefix
test_ so your userdata will not be resetted all the time. Initialization is done with the new class "TestEnvironment"
Creating new fixturesπ
Creating a new fixture is done with
install/db_backup.php. It writes a dump of all existing tables, so you have to remove the
test_*-tables before calling this.
Updating fixtures databaseπ
The fixtures need to be updated every time, the database scheme (e.I. the database version) changes. If you don't do this, you will get errors like this:

Test and development databaseπ
To distinguish between the two databases, we overwrite the
USER_AGENT before running the web_tester:
from tests/test_item_visibility.php
$this->addHeader('USER_AGENT: streber_unit_tester'); # will result in HTTP_USER_AGENT
In
index.php we check for this user_agent and add the prefix
test_ to
DB_TABLE_PREFIX. Before each test_case the test-database is completely recreated. After running all tests, the tables with
tests_* will be dropped from the database by executing a long sql-statement:
from tests/testsuite_pages
TestEnvironment::prepare('fixtures/remove_tables.sql');
Todoπ
Although the current setting already provides a lot of features, it's still pretty hackish. Following this should be adjusted:
- Streber should detect the web_tester user_agent and automatically use the
test_-tables.
TestEnvironment should provide a method the clean up test tables.
- Setup basic project environment as fixture for testing.
Things that urgently need to be testedπ
- Form submitting esp for complex things like Tasks and People.
- Correct escaping of all user data.
- Item visibility in project environments.
also see: