Using GAE Testbed with GAEUnit: Testing that email was sent

In my quest for testing if emails are being sent by my app engine app, I came across GAE Testbed.  GAE Testbed

… is a set of base test cases to make it simple to test the more complicated pieces of AppEngine’s framework (such as sending E-mail messages, the datastore, Memcache, etc.)

Since I’m already using GAEUnit as the unit testing framework for my app, I wanted to use GAE Testbed alongside GAEUnit so I only had to call one command (http://localhost:8080/test) to execute all my tests.  The documentation from the GAE Testbed home page is written to make it work alongside NoseGAE, so I decided to write one for GAEUnit.

Add GAEUnit to your app:

  1. Download the zipped archive of GAEUnit from its Google Code project hosting page.
  2. Extract the archive.
  3. From the folder extracted from the archive, copy to your app’s root folder.
  4. Add the following 2 lines to your app.yaml, directly below the line that says handlers::
    - url: /test.*
  5. (Optional) From the folder extracted from the archive, there’s a folder named sample_app and inside it is the modified version of the webtest module. Copy the webtest module (the entire folder containing and to the root of your app.

Add GAE Testbed to GAEUnit:

  1. Download the GAE Testbed tar gzipped archive from its Google Code project hosting page.
  2. Extract the archive.
  3. Inside the extracted archive is the gaetestbed module (it’s the folder named “gaetestbed”).  Copy the module to the root of your app.
  4. Create a file inside the test folder of the root of your app. For the sake of this example, let’s name it
  5. Using the example from the GAE Testbed Google Code project hosting page, add the following lines to
    import unittest
    from gaetestbed import MailTestCase
    class MyTestCase(MailTestCase, unittest.TestCase):
        def test_email_sent(self):
            send_email_to('') # Some method that sends e-mail...
            self.assertEqual(len(self.get_sent_messages()), 1)

Start your server and go to http://localhost:8080/test. You should notice that (an additional) 1/1 test was ran from http://localhost:8080/test.

* Many thanks to John Geewax for creating GAE Testbed.