I\'m about to embark on some large Python-based App Engine projects, and I think I should check with Stack Overflow\'s \"wisdom of crowds\" before committing to a unit-testing s
You don't need to write your own stubs - the SDK includes them, since they're what it uses to emulate the production APIs. Not all of them are suitable for use in unit-tests, but most are. Check out this code for an example of the setup/teardown code you need to make use of the built in stubs.
I might also add that Fixture has been very useful in my unit tests. It lets you create models in a declarative syntax, which it converts into stored entities that you can load in your tests. This way you have the same data set at the beginning of every test case!, which saves you from having to create data by hand at the start of every test. Here is an example, from the Fixture documentation: Given this model:
from google.appengine.ext import db
class Entry(db.Model):
title = db.StringProperty()
body = db.TextProperty()
added_on = db.DateTimeProperty(auto_now_add=True)
Your fixture would look like this:
from fixture import DataSet
class EntryData(DataSet):
class great_monday:
title = "Monday Was Great"
body = """\
Monday was the best day ever.
"""
Note however, that I ran into the following issues: 1. This bug, but the included patch does remedy it. 2. The datastore is not -by default- reset between test cases. So I use this to force a reset for each test case:
class TycoonTest(unittest.TestCase):
def setUp(self):
# Clear out the datastore before starting the test.
apiproxy_stub_map.apiproxy._APIProxyStubMap__stub_map['datastore_v3'].Clear()
self.data = self.load_data()
self.data.setup()
os.environ['SERVER_NAME'] = "dev_appserver"
self.after_setUp()
def load_data(self):
return datafixture.data(*dset.__all__)
def after_setUp(self):
""" After setup
"""
pass
def tearDown(self):
# Teardown data.
try:
self.data.teardown()
except:
pass
NoseGAE is a nose plugin that support unittests by automatically setting up the development environment and a test datastore for you. Very useful when developing on dev_appserver.
I use GAEUnit for my Google App Engine App and I am quite happy with the speed of the tests. The thing that I like about GAEUnit,and I am sure Webtest does it, is that it creates its own version for stubs of everything for testing leaving your "live" versions alone for testing.
So your datastore that you may be using for development will be left as is when you run your GAETests.
The SDK 1.4.3 Testbed API provides easy configuration of stub libraries for local integration tests.
Since 1.3.1 version of SDK there is the build-in unit test framework.
It is Java only right now but I feel like:
So does the author of this framework - Max Ross and he explicitly tells us about it in his I/O presentation "Testing techniques for Google App Engine"
Does anyone have any updates on this topic?