Skip to content

Testing

mjumbewu edited this page Sep 22, 2011 · 12 revisions

We want this project to be at a point, eventually, where an outside contributor can be confident that they are not breaking existing functionality when they write new code. Good coverage with automated unit tests is one way to get there.

For now, though, we want some reasonable assurance that when we write new code, we're not breaking legacy. First step in the testing strategy is to put up some characterization tests.

Python

To test Python, we are utilizing python-nose and unittest2.

Run Tests

To run the unit tests: nosetests tests/unittests/

You can also run the automated integration tests. In order to do so, you will want to set up a test database first. Just create an empty database (e.g., cbu_testing) that your database user has all permissions on. Also, add into your config file, in the database section, a line for the test database:

test_db: cbu_testing

Now, to run the tests: nosetests tests/integrationtests/

Integration tests load sample data into the database. The sample data files (fixtures) are stored in tests/integrationtests/sql/. If you want to use a sample data fixture in your tests, in derive your TestCase class from mixins.AppSetupMixin, and specify the fixture that you want to use. For example:

from mixins import AppSetupMixin

class Test_SomeSystem_component (AppSetupMixin, TestCase):
    fixtures = ['myfixture1.sql','myfixture2.sql']
    
    def test_that_it_does_something (self):
        ...

To create a new mixin, you can dump data from an existing database with mysqldump like so:

mysqldump -u cbu_user -p cbu_db --skip-triggers --compact --no-create-info --complete-insert --ignore_table=cbu_db.migrate_version

This will dump the INSERT commands, but not the commands to create the database tables. We ignore the migrate_version table because the data for that table is already in models.sql. The AppSetupMixin will load the database schema from the models.sql file.

NOTE: If you change your schema, you may have to regenerate the test data (depending on the nature of the schema changes).

Javascript

To test Javascript, we are utilizing Jasmine and EnvJasmine.

Set Up

EnvJasmine is managed with Git Submodules.

  1. git submodule init
  2. git submodule update

Run Tests

The following command will run all tests: ./tests/js/EnvJasmine/bin/run_test.sh --configFile=../../js/config.js

Browser

We use Selenium for high level, browser based, user interaction testing.

Installation

Follow the instructions in the following articles on how to get Selenium Server 2 running as a service. Selenium will then be running at port 4443.

Running Tests

Currently the best way to run these tests is to run each one manually.

  • Something similar to: python tests/selenium/test_home.py

We should be integrating this into a more centralized testing command.

Writing Tests