|
Readme
GAEUnit: Google App Engine Unit Test FrameworkVersion 1.2.5 http://code.google.com/p/gaeunit Copyright (c) 2008 George Lei and Steven R. Farley. All rights reserved. SUMMARYGAEUnit is a unit test framework that helps to automate testing of your Google App Engine application. With a single configuration (it can be completed within 30 seconds), your unit tests can be run in the real GAE app server environment. The results will be sent to web browser as an HTML web page. GAEUnit is simple. It contains only one file, gaeunit.py. Just copy that file into your application directory, add the test URL to app.yaml, you can start testing your apps for Google App Engine. WHAT'S NEW IN 1.2.5
INSTALLATION
- url: /test.* script: gaeunit.py WRITING TESTSWhen writing your test code, please follow the Python unit test coding conventions (http://docs.python.org/lib/writing-tests.html). Here are some simple rules:
Default OrganizationPut your test modules under the test directory. The structure of your web app files should look like the following: guestbook/
|---- app.yaml
|---- guestbook.py
|---- another_mod.py
|---- test/
|---- test_guestbook.py
|---- test_another_mod.pyBy default all modules in the test directory will be searched for TestCase subclasses. Package OrganizationIf you prefer to organize your tests differently, you can save them as packages with the addition of an _init_.py file, like this: guestbook/
|---- app.yaml
|---- guestbook.py
|---- another_mod.py
|---- packaged_tests/
|---- __init__.py
|---- test_guestbook.py
|---- test_another_mod.py__init__.py must contain a line like the following which explicitly lists all test modules: __all__ = ['test_guestbook', 'test_another_mod'] Note that certain options are not available when tests are packaged this way. For example, you cannot specify the name of a single test class or method to run with the name URL parameter. RUNNING TESTS
OptionsThere are a few options for running tests. These are set using the URL parameters defined below: nameRuns a specific test module, class, or method. Examples:
packageRuns all tests in a package. Example:
formatSets the content type of the test result. The value can be html for HTML format (the default) or plain for plain text format. Example:
|
Is it possible to run the tests in command line?
Put this on a .py file, and you are off to go with command line unittesting.
import urllib import sys ret = 0 for line in urllib.urlopen('http://localhost:8080/test?format=plain'): print line, if 'FAILED (' in line: ret = 1 sys.exit(ret)How do I fake a post request when testing an object?
GAEUnit was not designed to be run from the client side. It should live in the server side together with your service codes. I suggest you to refact your code to make it more testable. For example, separating the major logic into another method and keeping only routine code in your "get" or "post" method.
How can one get logging to print out in a unit test? I added the logging module, tried logging something and the output is simply lost in the web frontend.
Actually, I see the output back in the console running the dev_appserver, but it would be nice to be able to see the Traceback of a failed test along with debugging info in one place.
it's possible to use the django.test.client to simulate a client however i can't access pages that require a login. anyone know how to do this?
Is there a way to get access to the requestHandler from within the tests?
Great work, a few minor suggestions: it might be helpful to show gaeunit.py in the Default Organization above. It might also be helpful to note that anyone with a vanilla app.yaml handlers section should put the new entry before the /. entry.
Are the test modules run in alphabetical order?
By the way, you may want to mention that GAE unit isolates the test datastore from the development store.