Ferris provides utilities to test your application using nose and webtest. These utilites help you focus on testing your application instead of dealing with mocking App Engine.

Installing the nose plugin

FerrisNose is a nose plugin that allows you to run isolated Google App Engine tests. Install it via pip:

pip install ferrisnose


You may have to run this with sudo on linux and mac.


You may need to specify the –pre flag to pip.

Running tests

To run tests just use nose:

nosetests --with-ferris /app/tests


be sure to specify a path or nose will try to discover all tests which could fail in weird ways.

Writing tests for models

Models and other parts of the application that don’t involve HTTP/WSGI (such as services) can be tested using WithTestBed.

class ferris.tests.lib.WithTestBed(methodName='runTest')[source]

Here is a trivial example:

from app.models.cat import Cat
from ferris.tests.lib import WithTestBed

class CatTest(WithTestBed):
    def test_herding(self):
        Cat(name="Mr. Sparkles").put()

        assert Cat.query().count() == 2

Writing tests for controllers

Controller, components, and templates usually have to be tested within a full WSGI environment. This is where FerrisTestCase` comes in handy:

class ferris.tests.lib.FerrisTestCase(methodName='runTest')[source]

Provides all of the functionality of WithTestBed as well as a blank webtest instance available at self.testapp.

To add controllers to the testapp use addController().


Here’s an example of writing a test case for a single controller:

from app.controllers.cats import Cats
from ferris.tests.lib import FerrisTestCase

class CatsTest(FerrisTestCase):
    def test_herding_method(self):

        r = self.testapp.get('/cats')

        assert "Pickles" in r

Writing tests for the entire application

Sometimes you want the entire application to be up and running. In this instance you can use AppTestCase. Like FerrisTestCase it exposes a webtest instance via self.testapp but it automatically includes all controllers and plugins defined in your app.

class ferris.tests.lib.AppTestCase(methodName='runTest')[source]

This allows you to make requests to your application just as you would if the application were running:

from ferris.tests.lib import AppTestCase

class CatsTest(AppTestCase):
    def test_herding(self):
        Cat(name="Mr. Sparkles").put()

        r = self.testapp.get('/cats')

        assert "Pickles" in r
        assert "Mr. Sparkles" in r