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:
- Download the zipped archive of GAEUnit from its Google Code project hosting page.
- Extract the archive.
- From the folder extracted from the archive, copy
gaeunit.pyto your app’s root folder. - Add the following 2 lines to your app.yaml, directly below the line that says
handlers::- url: /test.* script: gaeunit.py
- (Optional) From the folder extracted from the archive, there’s a folder named
sample_appand inside it is the modified version of thewebtestmodule. Copy thewebtestmodule (the entire folder containingdebugapp.pyand__init__.py) to the root of your app.
Add GAE Testbed to GAEUnit:
- Download the GAE Testbed tar gzipped archive from its Google Code project hosting page.
- Extract the archive.
- Inside the extracted archive is the
gaetestbedmodule (it’s the folder named “gaetestbed”). Copy the module to the root of your app. - Create a file inside the
testfolder of the root of your app. For the sake of this example, let’s name ittest_mailer.py. - Using the example from the GAE Testbed Google Code project hosting page, add the following lines to
test_mailer.py:import unittest from gaetestbed import MailTestCase class MyTestCase(MailTestCase, unittest.TestCase): def test_email_sent(self): send_email_to('test@example.org') # Some method that sends e-mail... self.assertEmailSent(to='test@example.org') 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.
Related posts:

Thanks for the info, this will come in very handy I reckon! In general would you recommend starting off with GAEUnit or NoseGAE?
Hi Kevin. I have never used NoseGAE, but from what i’ve read, NoseGAE requires the installation of some other packages, which I think makes it not very portable and doesn’t ensure that my app will work on other servers. What I like about GAEUnit is that you already know that it comes with your app when you deploy it.
But I’m not sure. I’d like to know more about NoseGAE as well.
Does assertEmailSent get some info from the SMTP server, or does it just ensures that an EmailMessage was created and its “send” method invoked?
Thanks